+ 1
I want to write a list to a file?How should i do it?
7 Answers
+ 1
I meant like writing a list that contain items inside it to a file I've tried converting it first to str but it doesn't work
+ 1
I'll try those methods an see which one works an I'll get back to you, thanks by the way
0
the list is stored in an array ?
0
yes
0
okay after opening the file :
filename = open('anyfile.txt', 'w')
use a for loop to access array elements and write them like this :
for item in arrayname:
print>>filename, item
OR
for item in arrayname:
filename.write("%s\n" % item)
0
you can writes strings to a file. you can example write it in list format by going "[" + item + "]"