Reputation: 13
This is in my code:
if p1 == "something":
f = open("output.txt", "a")
f.write("Helloworld")
f.close()
And the hexdump shows this:
Expected output:
00000000: 48 65 6c 6c 6f 77 6f 72 Hellowor
00000008: 6c 64 ld
Current output
00000000: 0a 48 65 6c 6c 6f 77 6f .Hellowo
00000008: 72 6c 64 rld
PS: I have tried strip
, lstrip
, removing first character...
Upvotes: 1
Views: 481
Reputation: 833
I can't reproduce this.
Make sure you didn't create the file before, some text editors like to append a newline (0x0a) on save.
Use f = open("output.txt", "w")
to overwrite existing content in the file.
Upvotes: 2
Reputation: 2048
You're opening your file in append mode. Open your file in write mode, using 'w'
instead of 'a'
, or check whether you did not append anything to the file beforehand, as Turun Ambartanen said.
Upvotes: 1