printing bytes to stdout in Py3

Scott David Daniels Scott.Daniels at Acm.Org
Tue Feb 17 13:31:07 EST 2009

Casey wrote:
> ... Is this the 'official' way to do this?...  Why wouldn't you just use:
> print(bytes.decode(b'abc\n'), end='')

Because that code is incapable of sending bytes that cannot be
interpreted as encoded in the "default" encoding.  If you are
sending a picture, for example, all possible byte sequences might
show up.  If the default encoding is "utf-8", for example, there
are byte sequences which are illegal.  I suspect you are confused
by thinking each byte must map to a character; such an encoding
could never suffice for Chinese, for example.

--Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Python-list mailing list