6 Jun
2022
6 Jun
'22
9:08 p.m.
# 1. load from data storage class ConsistentContext: def __init__(self, filename): self.filename = filename self._load() def _load(self): try: with open(self.filename, 'rt') as file: self.data = [eval(line) for line in file] except: print(f'making {self.filename} new') def save(self): with open(self.filename + '.tmp', 'rt') as file: for idx, line in enumerate(data): if idx > 0: file.write('\n') file.write(repr(line)) def __del__(self): self.save()