[issue40863] bytes.decode changes/destroys line endings on windows

2020-06-04 Thread Eryk Sun
Change by Eryk Sun : -- stage: -> resolved status: open -> closed ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscr

[issue40863] bytes.decode changes/destroys line endings on windows

2020-06-04 Thread Paul Moore
Paul Moore added the comment: Because if you open a file in text mode (without "b" in the mode), Python writes \n (newline) characters as \r\n (carriage return, line feed) which are the Windows textfile representation of "Newline". >From the documentation of the built in open() function, "W

[issue40863] bytes.decode changes/destroys line endings on windows

2020-06-04 Thread Matthias Naegler
Matthias Naegler added the comment: I forgot something important. Using open with 'ab' works. >>> ...above code... with open("./test_binary.txt", "ab") as myfile: ... myfile.write(s.encode('utf-8')) -- ___ Python tracker

[issue40863] bytes.decode changes/destroys line endings on windows

2020-06-04 Thread Matthias Naegler
Matthias Naegler added the comment: Thanks Steven for your fast response. > The best way to see what your string actually contains is the print the repr: You are right. bytes.decode is correct. Im not a python expert, so thanks for the note about "repr". With repr(...) everything looks fine.

[issue40863] bytes.decode changes/destroys line endings on windows

2020-06-04 Thread STINNER Victor
Change by STINNER Victor : -- nosy: -vstinner ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.p

[issue40863] bytes.decode changes/destroys line endings on windows

2020-06-04 Thread Steven D'Aprano
Steven D'Aprano added the comment: You don't need `b = bytes([0x41, 0x0D, 0x0A])`, this will work just as well: b = b'\x41\x0D\x0A' and this is even better: b = b'A\r\n' > It seems like bytes.decode always replaces "\n" with "\r\n". What makes you say that? You are passing the out

[issue40863] bytes.decode changes/destroys line endings on windows

2020-06-04 Thread Matthias Naegler
New submission from Matthias Naegler : ``` # 0x0D, 13 = /r # 0x0A, 10 = /n print('test "\\r\\n"') print('-') b = bytes([0x41, 0x0D, 0x0A]) print("bytes: %s" % b) print("string: %s" % b.decode('utf8'), end='') # expected string: "A\r\n" # ressult string: "A\r\r\n" print('test "\\n"'