"Byte" type?
ajaksu
ajaksu at gmail.com
Thu Mar 12 21:03:27 EDT 2009
On Feb 15, 3:10 am, John Nagle <na... at animats.com> wrote:
> 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
<type 'bytearray'>
>>> bytearray()
bytearray(b'')
>>> bytearray(b'x')[0]
120
Does this explain it? It this different in 2.6?
Daniel
More information about the Python-list
mailing list