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
|
self.path = path
|
||||||
|
|
||||||
if path is None:
|
if path is None:
|
||||||
self.settings = {"abc" : "abftdc"}
|
self.settings = {}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.load_from_file(path)
|
self.load_from_file(path)
|
||||||
|
|
||||||
|
|
||||||
def load_from_file(self, path):
|
def load_from_file(self, path):
|
||||||
file = open(path, "r")
|
file = open(path, "r")
|
||||||
self.settings = eval(file.read())
|
self.settings = eval(file.read())
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
def save_settings(self):
|
def save(self, path):
|
||||||
file = open(self.path, "w")
|
file = open(path, "w")
|
||||||
|
file.write(str(self))
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
new_settings_str = "{\n"
|
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 += "\t" + repr(key) + ": " + repr(self.settings[key]) + ",\n"
|
||||||
|
|
||||||
new_settings_str = new_settings_str[:-2] + "\n}"
|
new_settings_str = new_settings_str[:-2] + "\n}"
|
||||||
|
|
||||||
file.write(new_settings_str)
|
return new_settings_str
|
||||||
file.close()
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return repr(self.settings)
|
return repr(self.settings)
|
||||||
|
|
Loading…
Reference in a new issue