[Python-ideas] bytes indexing behavior
leewangzhong+python at gmail.com
Fri Jul 8 01:03:45 EDT 2016
On Jul 6, 2016 2:40 PM, "Michael Selik" <michael.selik at gmail.com> wrote:
> 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:
>> > 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?
set(bytestring) == set(b'z')
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas