[+] Create toJson util method
This commit is contained in:
+2
-1
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
|
||||
from src.constants import dbPath
|
||||
from src.utils import toJson
|
||||
|
||||
|
||||
class Database:
|
||||
@@ -10,5 +11,5 @@ class Database:
|
||||
|
||||
def save(self):
|
||||
f = open(dbPath, 'w')
|
||||
f.write(json.dumps(self))
|
||||
f.write(toJson(self))
|
||||
f.close()
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import json
|
||||
|
||||
|
||||
def toJson(obj):
|
||||
return json.dumps(obj, default=lambda o: o.__dict__, sort_keys=True, indent=4)
|
||||
Reference in New Issue
Block a user