1import json
2a = [1,2,3]
3with open('test.txt', 'w') as f:
4 f.write(json.dumps(a))
5
6#Now read the file back into a Python list object
7with open('test.txt', 'r') as f:
8 a = json.loads(f.read())
1with open('your_file.txt', 'w') as f:
2 for item in my_list:
3 f.write("%s\n" % item)
4
1# define list of places
2places = ['Berlin', 'Cape Town', 'Sydney', 'Moscow']
3
4with open('listfile.txt', 'w') as filehandle:
5 for listitem in places:
6 filehandle.write('%s\n' % listitem)
7