[Python-3000] Last call for PEP 3137: Immutable Bytes and Mutable Buffer
Christian Heimes
lists at cheimes.de
Tue Oct 2 09:59:26 CEST 2007
Terry Reedy wrote:
> If orig_data were mutable (the new buffer, as proposed in the PEP), would
> not
>
> for i in range(len(orig_data)):
> orig_data[i] &= 0x1F
>
> do it in place? (I don't have .0a1 to try on the current bytes.)
Good catch!
Python 3.0a1 (py3k:58282, Sep 29 2007, 15:07:57)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
>>> orig_data = b"abc"
>>> orig_data
b'abc'
>>> for i in range(len(orig_data)):
... orig_data[i] &= 0x1F
...
>>> orig_data
b'\x01\x02\x03'
It'd be useful and more efficient if the new buffer type would support
the bit wise operations directly:
>>> orig_data &= 0x1F
TypeError: unsupported operand type(s) for &=: 'bytes' and 'int'
>>> orig_data &= b"\x1F"
TypeError: unsupported operand type(s) for &=: 'bytes' and 'bytes'
Christian
More information about the Python-3000
mailing list