+ 1

I want to write a list to a file?How should i do it?

2nd Mar 2018, 4:57 PM
Revolution
Revolution - avatar
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
2nd Mar 2018, 5:02 PM
Revolution
Revolution - avatar
+ 1
I'll try those methods an see which one works an I'll get back to you, thanks by the way
8th Mar 2018, 6:52 PM
Revolution
Revolution - avatar
0
the list is stored in an array ?
2nd Mar 2018, 5:03 PM
Michael Ehab Mikhail
Michael Ehab Mikhail - avatar
0
yes
2nd Mar 2018, 5:03 PM
Revolution
Revolution - avatar
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)
2nd Mar 2018, 5:08 PM
Michael Ehab Mikhail
Michael Ehab Mikhail - avatar
0
you can writes strings to a file. you can example write it in list format by going "[" + item + "]"
2nd Mar 2018, 10:05 PM
Markus Kaleton
Markus Kaleton - avatar