This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Matthias Naegler
Recipients Matthias Naegler, ezio.melotti, paul.moore, steve.dower, steven.daprano, tim.golden, zach.ware
Date 2020-06-04.18:01:00
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1591293660.99.0.571923534277.issue40863@roundup.psfhosted.org>
In-reply-to
Content
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.

Nevertheless, I get an additional \r in my output. Not sure if it is a problem of python, windows or just me.

I get the following output with the python interpretor:

Python 3.8.3rc1 (tags/v3.8.3rc1:802eb67, Apr 29 2020, 21:39:14) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdout.encoding
'utf-8'
>>> b =  b'A\r\nA'
>>> s = b.decode('utf-8')
>>> print(b)
b'A\r\nA'
>>> print(repr(s))
'A\r\nA'
>>> print(s)
A
A
>>> sys.stdout.write(s)
A
A4
>>> with open("./test.txt", "a") as myfile:
...     myfile.write(s)

This all looks right. But the file doesn't (see attached screenshot).

I also get an additional \r in the output file if i run the script throught "python test.py > piped.txt"
History
Date User Action Args
2020-06-04 18:01:01Matthias Naeglersetrecipients: + Matthias Naegler, paul.moore, tim.golden, ezio.melotti, steven.daprano, zach.ware, steve.dower
2020-06-04 18:01:00Matthias Naeglersetmessageid: <1591293660.99.0.571923534277.issue40863@roundup.psfhosted.org>
2020-06-04 18:01:00Matthias Naeglerlinkissue40863 messages
2020-06-04 18:01:00Matthias Naeglercreate