""save in-memory database object to file with custom formattingassume 'endrec ''enddb 'and '=>are not used in the dataassume db is dict of dictwarningeval can be dangerous it runs strings as codecould also eval(record dict all at oncecould also dbfile write(key '\ 'vs print(keyfile=dbfile)""dbfilename 'people-fileenddb 'enddb endrec 'endrec recsep '=>def storedbase(dbdbfilename=dbfilename)"formatted dump of database to flat filedbfile open(dbfilename' 'for key in dbprint(keyfile=dbfilefor (namevaluein db[keyitems()print(name recsep repr(value)file=dbfileprint(endrecfile=dbfileprint(enddbfile=dbfiledbfile close(def loaddbase(dbfilename=dbfilename)"parse data to reconstruct databasedbfile open(dbfilenameimport sys sys stdin dbfile db {key input(while key !enddbrec {field input(while field !endrecnamevalue field split(recseprec[nameeval(valuefield input(db[keyrec key input(return db if __name__ ='__main__'from initdata import db storedbase(dbthis is somewhat complex programpartly because it has both saving and loading logic and partly because it does its job the hard wayas we'll see in momentthere are better ways to get objects into files than by manually formatting and parsing them for simple tasksthoughthis does workrunning example - as script writes the database out to flat file it has no printed outputbut we can inspect the database file interactively after this script is runeither within idle or from console window where step storing records persistently