[issue38357] print adding extra bytes in hex above x7F

Ammar Askar report at bugs.python.org
Wed Oct 2 21:42:31 EDT 2019


Ammar Askar <ammar at ammaraskar.com> added the comment:

If you're trying to get raw bytes, you need to use

    print(b'\x80')

what's happening right now is that the '\x80' is treated as a unicode code point (see https://docs.python.org/3/howto/unicode.html#the-string-type), and when Python goes to print it, it gets encoded to the raw underlying bytes. Which, in the default encoding of utf-8 requires the extra byte.

>>> '\x80'.encode()
b'\xc2\x80'

----------
nosy: +ammar2
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38357>
_______________________________________


More information about the Python-bugs-list mailing list