[Python-ideas] bytes indexing behavior
Michael Selik
michael.selik at gmail.com
Wed Jul 6 14:37:05 EDT 2016
On Tue, Jun 7, 2016 at 4:30 PM Ethan Furman <ethan at stoneleaf.us> wrote:
> On 06/07/2016 12:57 PM, Nick Coghlan wrote:
> >
> https://www.python.org/dev/peps/pep-0467/#addition-of-optimised-iterator-methods-that-produce-bytes-objects
> >
> > If someone wanted to take that PEP and drive it through to resolution,
> > I'd be happy to hand it over (my recollection is that the sticking
> > point in the previous discussion was the proposed constructor changes,
> > so dropping those may make it easier to get the additional method
> > accepted).
>
> Split new thread to resolve that PEP.
>
What's the status of this PEP?
Does anyone dislike the suggestion of adding an iterbytes method?
I ran into this annoyance again yesterday. The natural way to ensure that
all bytes in a bytes object are a particular value (in this case b'z') is:
all(byte == b'z' for byte in bytestring)
It reads like natural language. Using ``ord`` would work in Python3, but
then my code would not be Python2-compatible. And it'd uselessly repeat the
call to ord a bunch of times.
all(byte == ord(b'z') for byte in bytestring)
Instead it seems the best way given the current behavior is to write:
len(bytestring) == bytestring.count(b'z')
While I wait for PEP 467, can anyone suggest a better way to write that?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160706/bb1435d6/attachment.html>
More information about the Python-ideas
mailing list