[Python-ideas] Bitwise operations on bytes class

Antoine Pitrou antoine at python.org
Wed Jun 18 17:51:36 CEST 2014


Le 18/06/2014 11:35, Nathaniel McCallum a écrit :
> On Mon, 2014-06-16 at 14:03 -0400, Nathaniel McCallum wrote:
>> I find myself, fairly often, needing to perform bitwise operations
>> (rshift, lshift, and, or, xor) on arrays of bytes in python (both bytes
>> and bytearray). I can't think of any other reasonable use for these
>> operators. Is upstream Python interested in this kind of behavior by
>> default? At the least, it would make many algorithms very easy to read
>> and write.
>
> So it seems to me that there is a consensus that something like this is
> a good idea, with perhaps the exception of Guido's reminder to not
> overpopulate the operators (is that a no for this proposal?).

Rather than adding new operations to bytes/bytearray, an alternative is 
a separate type ("bitview"?) which would take a writable buffer as 
argument and then provide the operations over that buffer.

It would allow make the operations compatible with other writable buffer 
types such as numpy arrays, etc.

Regards

Antoine.




More information about the Python-ideas mailing list