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

Antoine Pitrou antoine at python.org
Mon Aug 18 03:39:31 CEST 2014


Le 17/08/2014 19:41, Raymond Hettinger a écrit :
>
> The APIs have been around since 2.6 and AFAICT there have been zero
> demonstrated
> need for a special case for a single byte.  We already have a perfectly
> good spelling:
>     NUL = bytes([0])

That is actually a very cumbersome spelling. Why should I first create a 
one-element list in order to create a one-byte bytes object?

> The Zen tells us we really don't need a second way to do it (actually a
> third since you
> can also write b'\x00') and it suggests that this special case isn't
> special enough.

b'\x00' is obviously the right way to do it in this case, but we're 
concerned about the non-constant case.

The reason to instantiate bytes from non-constant integer comes from the 
unfortunate indexing and iteration behaviour of bytes objects.

Regards

Antoine.




More information about the Python-Dev mailing list