[Python-ideas] bytes indexing behavior

Jonathan Goble jcgoble3 at gmail.com
Tue Jun 7 01:48:48 EDT 2016


On Tue, Jun 7, 2016 at 1:06 AM, Serhiy Storchaka <storchaka at gmail.com> wrote:
> 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?

Actually, array.array implements the buffer protocol, and memoryview
can operate on any object that implements the buffer protocol. Thus,
you should be able to create a memoryview of an array.array instance
and operate on that (and in fact, you can, as I just tested it in an
interactive session).


More information about the Python-ideas mailing list