Arfrever Frehtes Taifersar Arahesis <arfrever....@gmail.com> added the comment:

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                                       .

----------
nosy: +Arfrever

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue38357>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to