Issue
I'm trying to write multiple lines of a string to a text file in Python3, but it only writes the single line.
e.g
Let's say printing my string returns this in the console;
>> print(mylongstring)
https://www.link1.com
https://www.link2.com
https://www.link3.com
https://www.link4.com
https://www.link5.com
https://www.link6.com
And i go to write that into a text file
f = open("temporary.txt","w+")
f.write(mylongstring)
All that reads in my text file is the first link (link1.com)
Any help? I can elaborate more if you want, it's my first post here after all.
Solution
Try closing the file:
f = open("temporary.txt","w+")
f.write(mylongstring)
f.close()
If that doesn't work try using:
f = open("temporary.txt","w+")
f.writelines(mylongstring)
f.close()
If that still doesn't work use:
f = open("temporary.txt","w+")
f.writelines([i + '\n' for i in mylongstring])
f.close()
Answered By - U13-Forward
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.