-
Saving a list to file
Hello,
I am writing a small program in python which is a list of my favourite anime. Now, I would like to save the list to file.
This is my code:
Code:
myanime=[]
for _ in range(10):
myanime.append(input("Enter a new entry :"))
print('My Favourite anime: \n' , *myanime, sep='\n - ')
This creates a list from the input value. I would now like to save the list to a file, after all the ten entries were added. I have tried with pickle, but it didn’t do what I wanted. How can I save my list to a file? Thank you.
-
something like this should work
Code:
myanime=[]
for _ in range(10):
newEntry = raw_input("Enter a new entry :")
print "My Favourite anime: \n" + newEntry + "\n - "
myanime.append(newEntry)
f= open("myanime.txt","a+")
for item in myanime:
f.write("%s\n" % item)
f.close()
St.O