[Python-ideas] bytes indexing behavior

Joao S. O. Bueno jsbueno at python.org.br
Tue Jun 7 10:39:12 EDT 2016


On 7 June 2016 at 08:27, Antoine Pitrou <antoine at python.org> wrote:
>
> Hi,
>
> While I prefer Python 2's indexing behaviour, IMHO that ship has sailed.
> Python 3.5 is probably seeing massive adoption now, and by introducing
> another behaviour switch we only confuse users and make their lives
> miserable.
>
> Let's move on and stop obsessing about errors made in the past.  Every
> language has some of those.
>

+1

Why not just stick in a new attribute over withch one can iterate as 1
byte "bytes sequence" instead?
Backwards compatible, and everyone gets happy:

for code, onebyte in zip(mybytes, mybytes.as_bytes):
     assert code == ord(onebyte)

I just can't view how any other thing could justify a major
breakearage in backward compatibility that would take
another 10-12 years to settle.  Maybe just add an "as_ints" iterator
as well, and deprecate interation on the
object itself - but reverse the behavior should just be a major no no
as in "python 4 scale" major no no!

And on the other hand, 'bytearray's have always behaved this way, even
in Python 2 - and it is
actually quite handy.

> Regards
>
> Antoine.
>


More information about the Python-ideas mailing list