diff --git a/data_file.py b/data_file.py index 29143c0..8280726 100644 --- a/data_file.py +++ b/data_file.py @@ -1,7 +1,6 @@ #!/usr/bin/python3 import json -from dataclasses import dataclass class DictFile: @@ -99,3 +98,19 @@ class DataclassJSONFile: def __len__(self): return len(self.class_instance.__dict__) + + +def load_dataclass_json(dataclass, file_path: str): + file = open(file_path, "r") + class_dict = json.load(file) + file.close() + + return dataclass(**class_dict) + + +def save_dataclass_json(class_instance, file_path: str): + class_dict = class_instance.__dict__ + + file = open(file_path, "w") + json.dump(class_dict, file) + file.close()