[Python-Dev] Fwd: PEP 467: Minor API improvements for bytes & bytearray

Chris Barker chris.barker at noaa.gov
Mon Aug 18 22:37:32 CEST 2014

On Mon, Aug 18, 2014 at 1:06 PM, Terry Reedy <tjreedy at udel.edu> wrote:

> The byte scalar is an int in range(256). Bytes is an array of such.

then why the complaint about iterating over bytes producing ints? Ye,s a
byte owuld be pretty much teh same as an int, but it would have
restrictions - useful ones.

 numpy has a scalar type for every type it supports -- this is a GOOD
>> THING (tm):
>> In [56]: type(a[1])
>> Out[56]: numpy.uint8
>> In [57]: a[1].shape
>> Out[57]: ()
>> The lack of a  character type is a major source of "type errors" in
>> python (the whole list of strings vs a single string problem -- both
>> return a sequence when you index into them or iterate over them)
> This is exactly what iterbytes would do  -- yields bytes of size 1.

as I understand it, it would yield a bytes object of length one -- that is
a sequence that _happens_ to only have one item in it -- not the same thing.

Note above. In numpy, when you index out of a 1-d array you get a scalar --
with shape == ()  -- not a 1-d array of length 1. And this is useful, as it
provide s clear termination point when you drill down through multiple

I often wish I could do that with nested lists with strings at the bottom.

[1,2,3] is a sequence of numbers

"this" is a sequence of characters -- oops, not it's not, it's a sequence
of sequences of sequences of ...

I think it would be cleaner if bytes was a sequence of a scalar byte object.

This is a bigger deal for numpy, what with its n-dimensional arrays and
many reducing operations, but the same principles apply.



Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140818/565ca2e8/attachment.html>

More information about the Python-Dev mailing list