"Byte" type?

Steve Holden steve at holdenweb.com
Sun Feb 15 08:41:17 EST 2009


Erik Max Francis wrote:
> John Nagle 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.
> 
> There's no distinction byte type.  A single character of a bytes type is
> also a bytes.
> 
Beware, also, that in 2.6 the "bytes" type is essentially an ugly hack
to enable easier forward compatibility with the 3.X series ...

regards
 Steve
-- 
Steve Holden        +1 571 484 6266   +1 800 494 3119
Holden Web LLC              http://www.holdenweb.com/




More information about the Python-list mailing list