fix: rw savefiles

This commit is contained in:
Didier Slof 2022-12-09 11:05:13 +01:00
parent 82ce01b85b
commit 2b5e72460a
Signed by: didier
GPG key ID: 01E71F18AA4398E5

View file

@ -10,13 +10,13 @@ class SaveFile(dict):
if not os.path.exists(_dir): if not os.path.exists(_dir):
os.makedirs(_dir) os.makedirs(_dir)
if os.path.exists(self.path): if os.path.exists(self.path):
with open(self.path) as f: with open(self.path, 'w+') as f:
self.update(json.loads(f.read())) self.update(json.loads(f.read()))
else: else:
self.save() self.save()
def save(self): def save(self):
with open(self.path, 'a+') as f: with open(self.path, 'w+') as f:
f.write(json.dumps(self, indent=1)) f.write(json.dumps(self, indent=1))
def __getitem__(self, key): def __getitem__(self, key):