import json import os.path class File(object): "Holds controller state in the file" def __init__(self, filename=None): self.filename = filename def present(self): os.path.isfile(self.filename) def load(self): if self.filename is None: raise ClassNotReadyException("Filename not set!") with open(self.filename) as input_file: self.data = json.load(input_file) def save(self): if self.filename is None: raise ClassNotReadyException("Filename not set!") if self.data is None: raise ClassNotReadyException("Data not loaded!") with open(self.filename, 'w') as out_file: json.dump(self.data, out_file)