"Christian Heimes" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
| 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'

Thanks for testing this!  Glad it worked.  This sort of thing makes having 
bytes/buffer[i] an int a plus.  (Just noticed, PEP accepted.)

| 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'

This sort of broadcast behavior seems like numpy territory to me.  Or 
better for a buffer subclass.  Write it first in Python, using loops like 
above (partly for documentation and other implementations), then in C when 
interest and usage warrents.

| >>> orig_data &= b"\x1F"
| TypeError: unsupported operand type(s) for &=: 'bytes' and 'bytes'

Ugh is my response.  Stick with the first ;-).

Terry Jan Reedy



_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to