This is the code I use:
with open(\'database.txt\', \'w\') as f: for item in booklist: f.write(\'%s\\n\' % item) f.close()
It