#!/usr/bin/python3 class Settings: def __init__(self, path: str=None): self.path = path if path is None: self.settings = {"abc" : "abftdc"} else: self.load_from_file(path) def load_from_file(self, path): file = open(path, "r") self.settings = eval(file.read()) file.close() def save_settings(self): file = open(self.path, "w") new_settings_str = "{\n" for key in self.settings.keys: new_settings_str += "\t" + repr(key) + ": " + repr(self.settings[key]) + ",\n" new_settings_str = new_settings_str[:-2] + "\n}" file.write(new_settings_str) file.close() def __repr__(self): return repr(self.settings) def __getitem__(self, key): return self.settings[key] def __setitem__(self, key, value): self.settings[key] = value def __delitem__(self, key): self.settings.pop(key) def __iter__(self): return self.settings def __len__(self): return len(self.settings)