On 8/18/2014 12:04 PM, Chris Barker wrote:
On Sun, Aug 17, 2014 at 2:41 PM, Barry Warsaw <barry@python.org <mailto:barry@python.org>> wrote:
I think the biggest API "problem" is that default iteration returns integers instead of bytes. That's a real pain.
what is really needed for this NOT to be a pain is a byte scalar.
The byte scalar is an int in range(256). Bytes is an array of such.
numpy has a scalar type for every type it supports -- this is a GOOD THING (tm):
In [53]: a = np.array((3,4,5), dtype=np.uint8)
In [54]: a Out[54]: array([3, 4, 5], dtype=uint8)
In [55]: a[1] Out[55]: 4
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.
Anyway, the character ship has long since sailed, but maybe a byte scalar would be a good idea?
And FWIW, I think the proposal does make for a better, cleaner API.
-- Terry Jan Reedy