Added some comments.

This commit is contained in:
The Wobbler 2024-02-25 14:48:51 +01:00
parent 9bb90c14f1
commit 9a52203ba2

View file

@ -11,7 +11,7 @@ class DictFile:
def __init__(self, path: str=None):
self.path = path
if path is None:
if path is None: # create empty settings dict if path is none else load settings from file
self.settings = {}
else:
@ -30,7 +30,7 @@ class DictFile:
file.write(str(self))
file.close()
def __str__(self):
def __str__(self): # make the dict not be just one line
new_settings_str = "{\n"
for key in self.settings:
new_settings_str += "\t" + repr(key) + ": " + repr(self.settings[key]) + ",\n"
@ -64,7 +64,7 @@ class DataclassJSONFile:
self.dataclass = dataclass
self.class_instance = class_instance
if class_instance is None:
if class_instance is None: # load the class instance from the file if it is None
self.load_from_file(file_path)
def load_from_file(self, file_path):
@ -100,6 +100,7 @@ class DataclassJSONFile:
return len(self.class_instance.__dict__)
# these 2 functions do the exact same thing as in the class above
def load_dataclass_json(dataclass, file_path: str):
file = open(file_path, "r")
class_dict = json.load(file)