0
How many different way to add a list in .txt file in python???
5 Answers
+ 5
You can try this:
f = open("hello.txt","a+")
lst1 = "['Paul Brown', 'Coding for fun', '1234567890', 19.50]"
f.write(lst1)
f.close()
f = open("hello.txt","a+")
lst2 = "['Mary White', 'The long way', '123454321', 22.90]"
f.write(lst2)
f.close()
f=open("hello.txt","r")
print(f.read())
+ 4
I suppose you already have a .txt file and you want to add new data to the end of the file?
+ 3
hi, if you would have run the code exactly as it is shown on my post - it will work properly. This is in sololearn and also in other IDE.
lst1 and lst2 are a list but inside quotes, do itâs a string that contains a list.
0
Actually I want to add a list in . txt entered by user in the program. Suppose we have to store data of the user
0
Your lst1 is a list and we can't write like this (f.write(lst1) it will give an error coz inside write we can't put a list)