In python 2


#1
def storeDbase(db, dbfilename=dbfilename):
   "formatted dump of database to flat file"
   dbfile = open(dbfilename, 'w')
   for key in db:
   print(key, file=dbfile)
   for (name, value) in db[key].items():
       print(name + RECSEP + repr(value), file=dbfile)
       print(ENDREC, file=dbfile)
     print(ENDDB, file=dbfile)
     dbfile.close()

in above program print(key,file=dbfile) how can it be written in python2


#2

File objects have methods for writing to them, use those instead (I’d use that in python3 as well, print is foremost a helper for writing to sys.stdout which is just another file object)