Sep-14-2019, 09:33 PM
There are small database packages that is fine for this eg TinyDB or dataset.
I have tutorial about dataset here.
Can do test with TinyDB,will store and also do trick(**) to recreate class instantiating from DB.
Load again.
I have tutorial about dataset here.
Can do test with TinyDB,will store and also do trick(**) to recreate class instantiating from DB.
>>> from tinydb import TinyDB, Query >>> db = TinyDB('db.json') >>> doggo = Dog("Spot", "Black and White", 2) >>> fido = Dog("Fiff", "Brown", 4) >>> db.insert(doggo.__dict__) 1 >>> db.insert(fido.__dict__) 2 >>> db.all() [{'name': 'Spot', 'color': 'Black and White', 'age': 2}, {'name': 'Fiff', 'color': 'Brown', 'age': 4}] >>> exit()Now have date in
db.json
.Load again.
>>> from tinydb import TinyDB, Query >>> db = TinyDB('db.json') >>> find = Query() >>> doggo = db.search(find.name == 'Spot')[0] >>> doggo {'name': 'Spot', 'color': 'Black and White', 'age': 2} # Now the trick,using data from DB to recreate the class >>> doggo = Dog(**doggo) >>> doggo.name 'Spot' >>> doggo.color 'Black and White'