[Python-Dev] Fwd: PEP 467: Minor API improvements for bytes & bytearray
tjreedy at udel.edu
Mon Aug 18 22:06:06 CEST 2014
On 8/18/2014 12:04 PM, Chris Barker wrote:
> On Sun, Aug 17, 2014 at 2:41 PM, Barry Warsaw <barry at python.org
> <mailto:barry at python.org>> wrote:
> I think the biggest API "problem" is that default iteration returns
> 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 : a = np.array((3,4,5), dtype=np.uint8)
> In : a
> Out: array([3, 4, 5], dtype=uint8)
> In : a
> Out: 4
> In : type(a)
> Out: numpy.uint8
> In : a.shape
> Out: ()
> 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
More information about the Python-Dev