Reputation: 834
I am writing strings to a text document using python 2.7
I am not adding then "\n" newline character until the very end of each line, yet when I open up the text document, newlines are being created on their own. What am I doing wrong?
My code looks like this:
w.write(ID + " " + Name + " " + x + " " + y + " " + "\n")
w.write(ID2 + " " + Name2 + " " + x2 + " " + y2 + " " + "\n")
My text document looks like this:
1----Polyline1----0.567
----0.837
2----Polyline2----0.928
----0.253
^^^Those are spaces, not dashes
Upvotes: 0
Views: 264
Reputation: 798506
Because you forgot to strip the newlines from x
and x2
after reading them.
Also, ␣ and ␢.
Upvotes: 2