Syntax error for python me in this

dbfile = open(dbfilename, 'w')
for key in db:
    print(key, file=dbfile)

in the above code,how should i write in python 2 for line 3.when i try in python 3 i get no errors but in python 2 i get errors

You would normally do:


Python 3 might have added the file= option but I don’t use it. I use the file api