Added a to_str function for all classes. __str__ function uses it. highscores_data uses the to_str function for saving.
This commit is contained in:
+10
-1
@@ -28,7 +28,7 @@ class Table:
|
||||
Returns:
|
||||
str: Table class as a string
|
||||
"""
|
||||
return json.dumps(self.to_dict(), indent=4)
|
||||
return self.to_str()
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, table_name: str, data: dict):
|
||||
@@ -129,3 +129,12 @@ class Table:
|
||||
data["categories"][category.name] = category.to_dict()
|
||||
|
||||
return data
|
||||
|
||||
def to_str(self) -> str:
|
||||
"""
|
||||
Returns Table object as a string.
|
||||
|
||||
Returns:
|
||||
str: string of json representation of Table
|
||||
"""
|
||||
return json.dumps(self.to_dict(), indent=4)
|
||||
|
||||
Reference in New Issue
Block a user