[Python-3000] about bytes
Guido van Rossum
guido at python.org
Fri Jun 27 20:08:21 CEST 2008
On Fri, Jun 27, 2008 at 5:16 AM, Facundo Batista
<facundobatista at gmail.com> wrote:
> 2008/6/26 Georg Brandl <g.brandl at gmx.net>:
>
>> Yes. Bytes objects are sequences of bytes, which are integers.
>> So, in short, this is the way they work.
>
> I think that the OP confusion comes from the representation.
>
> We have a data type called bytes. They are sequences of bytes. So, I build one:
>
>>>> b = bytes((72, 105))
>
>
> Then I check:
>
>>>> b[0]
> 72
>>>> b[1]
> 105
>
>
> Great! But:
>
>>>> b
> b'Hi'
>
>
> Why I see two letters? Wasn't them bytes? :o
>
> I know that is great to represent bytes between 32 and 127 as letters,
> and this has several compatibility details, but I think that the
> surprise comes from that place.
>
> If the behaviour were the following....
>
>>>> b
> b((72, 105))
>
> ...it would be less surprising.
Only if you didn't know that b'' is an alternative to bytes(). The b''
notation is so much more compact and so much more helpful that I
really don't want to go back to it. We will somehow have to deal with
this through education and documentation.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list