You are about to write a list element to a file. For example,
#PythonFile
mylist = ["hello", "3"]
file = open("myfile.txt", "w")
file.writelines(["%s\n" % item for item in mylist])
When you run myfile.txt
hello
3
Let's come out together.
My cord is working well right now, but I'm not sure if I'm using it well.
list file file-io python newline
Usually
for item in thelist:
thefile.write("%s\n" % item)
#or
for item in thelist:
print>>thefile, item
It's written as. If you're going to stick to one line, I think it's better to take out []
.
© 2024 OneMinuteCode. All rights reserved.