<div dir="ltr"><br><br><div class="gmail_quote">On Mon, Oct 6, 2008 at 1:30 AM, Bryan Olson <span dir="ltr"><<a href="mailto:fakeaddress@nowhere.org">fakeaddress@nowhere.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
<br>
In Python 2.6, the name 'bytes' is defined, and bound to str. The 2.6 assignment presents some pitfalls. Be aware.<br>
<br>
Consider constructing a bytes object as:<br>
<br>
b = bytes([68, 255, 0])<br>
<br>
In Python 3.x, len(b) will be 3, which feels right.<br>
<br>
In Python 2.6, len(b) will be 12, because b is the str, '[68, 255, 0]'.<br>
<br>
<br>
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.</blockquote>
</div><br>You could just use a bytearray instead of a normal list.<br><br>Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04) <br>[GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin<br>Type "help", "copyright", "credits" or "license" for more information.<br>
>>> a = bytearray([65,66,67])<br>>>> a<br>bytearray(b'ABC')<br>>>> a[1] = 70<br>>>> a<br>bytearray(b'AFC')<br>>>> bytes(a)<br>'AFC'<br><br></div>