"Byte" type?

A

ajaksu

With "bytearray", the element type is considered to be "unsigned byte",
or so says PEP 3137: "The element data type is always 'B' (i.e. unsigned byte)."

Let's try:

Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on
win32
xx = b'x'
repr(xx) "'x'"
repr(xx[0]) "'x'"
repr(xx[0][0]) "'x'"

But that's not what "repr" indicates. The bytearray element is apparently
being promoted to "bytes" as soon as it comes out of the array.

Except for the detail that b'x' is not a bytearray:

../trunk-py/python
Python 2.7a0 (trunk, Feb 24 2009, 10:30:17)
[...]
bytearray
bytearray() bytearray(b'')
bytearray(b'x')[0]
120

Does this explain it? It this different in 2.6?

Daniel
 
A

ajaksu

     According to PEP 3137, there should be no distinction between
the two for read purposes.  In 2.6, there is.  That's a bug.

No, it's not. It's well documented: http://docs.python.org/whatsnew/2.6.html#pep-3112-byte-literals

If that's not precise enough, you can read there that
For future compatibility, Python 2.6 adds bytes as a synonym
for the str type, and it also supports the b'' notation.
The 2.6 str differs from 3.0’s bytes type in various ways;
    No, it's broken.  PEP 3137 says one thing, and the 2.6 implementation
does something else.  So code written for 2.6 won't be ready for 3.0.
This defeats the supposed point of 2.6.

No, you're misunderstanding the scope of PEP 3137, the goal of the
bytes alias in 2.6 and the point of 2.6. Also, you're missing that
this is documented, expected and well reasoned behavior.

So, you're leaping to wrong conclusions from uninformed, broken
premises, all the while calling things broken and dumb. It's like the
artistic gymnastics all-around troll finals.

Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top