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 Arfrever
Recipients Arfrever, Artificial, ammar2
Date 2019-10-03.01:53:47
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1570067627.38.0.114305911034.issue38357@roundup.psfhosted.org>
In-reply-to
Content
However print() called with non-str argument would firstly call str() on it, which is most likely not what reporter wanted:

>>> print(b'\x80')
b'\x80'
>>> str(b"\x80")
"b'\\x80'"
>>> print(str(b"\x80"))
b'\x80'

$ python -c "print(b'\x80')" > test.txt
$ xxd test.txt
00000000: 6227 5c78 3830 270a                      b'\x80'.


Proper solution is to write to files opened in binary mode, which in case of stdout and stderr means to use sys.stdout.buffer and sys.stderr.buffer:

>>> sys.stdout.buffer.write(b"\x80")
�1

$ python -c "import sys; sys.stdout.buffer.write(b'\x80')" > test.txt
$ xxd test.txt
00000000: 80                                       .
History
Date User Action Args
2019-10-03 01:53:47Arfreversetrecipients: + Arfrever, ammar2, Artificial
2019-10-03 01:53:47Arfreversetmessageid: <1570067627.38.0.114305911034.issue38357@roundup.psfhosted.org>
2019-10-03 01:53:47Arfreverlinkissue38357 messages
2019-10-03 01:53:47Arfrevercreate