[Python-Dev] Python 3.x and bytes

Nick Coghlan ncoghlan at gmail.com
Wed May 18 05:13:32 CEST 2011

On Wed, May 18, 2011 at 8:27 AM, Ethan Furman <ethan at stoneleaf.us> wrote:
> On the one hand we have the 'bytes are ascii data' type interface, and on
> the other we have the 'bytes are a list of integers between 0 - 256'
> interface.

No. Bytes are a list of integers between 0-256. End of story. Using
them to represent text as well was precisely the problem with 2.x
8-bit strings, since the boundaries got blurred.

However, as a matter of practicality, many byte-oriented protocols use
ASCII to make elements of the protocol readable by humans. The
"text-like" elements of the bytes and bytearray types are a concession
to the existence of those protocols. However, that doesn't make them
text - they're still binary data streams. If you want to treat them as
text, convert them to "str" objects first (e.g. that's what
urlib.urlparse does internally in order to operate on bytes and
bytearray instances).


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list