From 6ac3a804837738f8d0d2f561db0d989d7268b19b Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Sun, 5 Nov 2023 16:14:16 +0100 Subject: [PATCH] Added __str__() to settings class. --- settings.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/settings.py b/settings.py index 428395c..70817cf 100644 --- a/settings.py +++ b/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)