[Python-ideas] Fixing the Python 3 bytes constructor

Antoine Pitrou solipsis at pitrou.net
Fri Mar 28 18:42:41 CET 2014


On Fri, 28 Mar 2014 18:31:58 +0100
"Philipp A." <flying-sheep at web.de> wrote:
> even if some people don’t like it, the iterating over bytes objects makes
> perfect sense.
> 
> in every statically typed language, a byte is most commonly repesented as
> an integer in the range [0,255].
> 
> the annoyance has two sources:
> 
>    1.
> 
>    python 2 byte strings (aka “native strings”) behaved like that (and
>    unicode strings behave like that because python has no char type)
>     2.
> 
>    byte strings are represented like strings, including ascii-compatible
>    parts as if they were ASCII text.

The actual source isn't merely cultural. It's that most of the time,
bytes objects are used as containers of arbitrary binary data, not
as arrays of integers (on which you would do element-wise arithmetic
calculations, for instance).

So, even if the current behaviour makes sense, it's not optimal for the
common uses of bytes objects.

Regards

Antoine.




More information about the Python-ideas mailing list