[Python-ideas] Fixing the Python 3 bytes constructor

Ethan Furman ethan at stoneleaf.us
Sat Mar 29 22:09:36 CET 2014


On 03/29/2014 01:59 PM, Alexander Heger wrote:
>>
>> I'm also +1 on Benjamin's idea of the iterate-as-bytes addition. That just
>> leaves the inability to index into bytes and get back a single as the
>> biggest annoyance in the bytes API.
>
> The issue remains that there is no single byte type, but what is
> returned is bytes type over which, again, you can iterate.  This is
> different from a tuple of integers, when you iterate over that, you
> get integers not length-one tuples of integers.  The issue, I think,
> originates from the string concept where iteration also return a
> string not a character - which python does not have.  A logical
> extension would be to have to have character and byte types that are
> returned when iterating of strings and bytes.  This is like taking a
> giraffe out of a zoo and still calling the result a (small) zoo.  Or
> calling a can of tuna a grocery store.

Nice examples.  The problem is that one *can* say:

    b'a'

and get a 'bytes' object of length one, and then quite naturally one would then try something like

    b'abc'[0] == b'a'

and that will fail, even though it *looks* correct.

--
~Ethan~


More information about the Python-ideas mailing list