Added __str__() to settings class.
This commit is contained in:
parent
2ab5e56969
commit
6ac3a80483
1 changed files with 9 additions and 6 deletions
15
settings.py
15
settings.py
|
@ -5,27 +5,30 @@ class Settings:
|
|||
self.path = path
|
||||
|
||||
if path is None:
|
||||
self.settings = {"abc" : "abftdc"}
|
||||
self.settings = {}
|
||||
|
||||
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")
|
||||
def save(self, path):
|
||||
file = open(path, "w")
|
||||
file.write(str(self))
|
||||
file.close()
|
||||
|
||||
def __str__(self):
|
||||
new_settings_str = "{\n"
|
||||
for key in self.settings.keys:
|
||||
for key in self.settings:
|
||||
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()
|
||||
return new_settings_str
|
||||
|
||||
def __repr__(self):
|
||||
return repr(self.settings)
|
||||
|
|
Loading…
Reference in a new issue