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:
alwayscompiling
2022-08-03 22:35:27 -04:00
parent 66ace947c6
commit 6f4322bf6a
5 changed files with 41 additions and 5 deletions
+10 -1
View File
@@ -30,7 +30,7 @@ class Category:
Returns:
str: Category class as a string
"""
return json.dumps(self.to_dict(), indent=4)
return self.to_str()
@classmethod
def from_dict(cls, name: str, data: dict):
@@ -158,3 +158,12 @@ class Category:
data["scores"][score.user] = score.value
return data
def to_str(self) -> str:
"""
Returns Category object as a string.
Returns:
str: string of json representation of Category
"""
return json.dumps(self.to_dict(), indent=4)