Added some comments.
This commit is contained in:
parent
9bb90c14f1
commit
9a52203ba2
1 changed files with 4 additions and 3 deletions
|
@ -11,7 +11,7 @@ class DictFile:
|
||||||
def __init__(self, path: str=None):
|
def __init__(self, path: str=None):
|
||||||
self.path = path
|
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 = {}
|
self.settings = {}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
@ -30,7 +30,7 @@ class DictFile:
|
||||||
file.write(str(self))
|
file.write(str(self))
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self): # make the dict not be just one line
|
||||||
new_settings_str = "{\n"
|
new_settings_str = "{\n"
|
||||||
for key in self.settings:
|
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"
|
||||||
|
@ -64,7 +64,7 @@ class DataclassJSONFile:
|
||||||
self.dataclass = dataclass
|
self.dataclass = dataclass
|
||||||
self.class_instance = class_instance
|
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)
|
self.load_from_file(file_path)
|
||||||
|
|
||||||
def load_from_file(self, file_path):
|
def load_from_file(self, file_path):
|
||||||
|
@ -100,6 +100,7 @@ class DataclassJSONFile:
|
||||||
return len(self.class_instance.__dict__)
|
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):
|
def load_dataclass_json(dataclass, file_path: str):
|
||||||
file = open(file_path, "r")
|
file = open(file_path, "r")
|
||||||
class_dict = json.load(file)
|
class_dict = json.load(file)
|
||||||
|
|
Loading…
Reference in a new issue