[Python-ideas] Fixing the Python 3 bytes constructor

Ryan Hiebert ryan at ryanhiebert.com
Fri Mar 28 18:52:37 CET 2014


On Fri, Mar 28, 2014 at 12:42 PM, Antoine Pitrou <solipsis at pitrou.net>wrote:

> 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.


I don't see bytes as integers, but as representations of integers, that
typically come in a stream or array. Using an integer to represent
that byte sometimes makes sense, but sometimes you wish to refer
to the representation of the integer (the byte), not the integer itself.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140328/d2db8b2e/attachment.html>


More information about the Python-ideas mailing list