def read_data_file(self): try: handler = open(self._data_file) except (OSError, IOError): # Create default config file if non-existant handler = open(self._data_file, 'w+') handler.write(utils.serialize(BACKUP_DEFAULT_SETTINGS)) handler.seek(0) finally: with handler as f: data_file = f.read() self._data = utils.deserialize(data_file) handler.close()
def write_data_file(self): handler = open(self._data_file, 'w+') handler.write(utils.serialize(self._data)) handler.close()