On Mon, Oct 6, 2008 at 1:30 AM, Bryan Olson <[EMAIL PROTECTED]> wrote:
> > > In Python 2.6, the name 'bytes' is defined, and bound to str. The 2.6 > assignment presents some pitfalls. Be aware. > > Consider constructing a bytes object as: > > b = bytes([68, 255, 0]) > > In Python 3.x, len(b) will be 3, which feels right. > > In Python 2.6, len(b) will be 12, because b is the str, '[68, 255, 0]'. > > > I'm thinking I should just avoid using 'bytes' in Python 2.6. If there's > another Python release between 2.6 and 3.gold, I'd advocate removing the > pre-defined 'bytes', or maybe defining it as something else. You could just use a bytearray instead of a normal list. Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) [GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> a = bytearray([65,66,67]) >>> a bytearray(b'ABC') >>> a[1] = 70 >>> a bytearray(b'AFC') >>> bytes(a) 'AFC'
-- http://mail.python.org/mailman/listinfo/python-list