[Python-ideas] bytes indexing behavior
Serhiy Storchaka
storchaka at gmail.com
Tue Jun 7 01:06:10 EDT 2016
On 07.06.16 07:48, Guido van Rossum wrote:
> On Monday, June 6, 2016, Serhiy Storchaka
> <storchaka at gmail.com
> <mailto:storchaka at gmail.com>> wrote:
>
> On 06.06.16 23:28, Guido van Rossum wrote:
>
> I think the approach using a new method for the old behavior is
> workable. Maybe we should add another (temporary) new method for
> the new
> behavior.
>
> The magic object approach is too magical.
>
> We should do the same for bytearray and memoryview.
>
>
> I often use bytearray and memoryview as arrays of ints.
>
>
> Really short ints. :-). But you should really use the array module instead.
Yes, ints of known width (even 1-bit ints in sre_compile.py). Using the
array module requires additional copying. Aren't bytearray and
memoryview here for avoiding unnecessary copying?
> Anyway we should do this for all three or for none.
I think representing bytes as an array of ints was good decision. If you
need indexing to return a substring, you should use str instead. It is
as well memory efficient thanks to PEP 393.
More information about the Python-ideas
mailing list