<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Tue, Jun 7, 2016 at 4:30 PM Ethan Furman <<a href="mailto:ethan@stoneleaf.us">ethan@stoneleaf.us</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 06/07/2016 12:57 PM, Nick Coghlan wrote:<br>> <a href="https://www.python.org/dev/peps/pep-0467/#addition-of-optimised-iterator-methods-that-produce-bytes-objects" rel="noreferrer" target="_blank">https://www.python.org/dev/peps/pep-0467/#addition-of-optimised-iterator-methods-that-produce-bytes-objects</a><br>
><br>
> If someone wanted to take that PEP and drive it through to resolution,<br>
> I'd be happy to hand it over (my recollection is that the sticking<br>
> point in the previous discussion was the proposed constructor changes,<br>
> so dropping those may make it easier to get the additional method<br>
> accepted).<br><br>Split new thread to resolve that PEP.<br></blockquote><div><br></div><div>What's the status of this PEP?</div><div>Does anyone dislike the suggestion of adding an iterbytes method?</div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">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:</span></div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5"> all(byte == b'z' for byte in bytestring)</span></div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">It reads like natural language. </span><span style="line-height:1.5">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.</span></div><div><span style="line-height:1.5"><br></span></div><div> all(byte == ord(b'z') for byte in bytestring)</div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">Instead it seems the best way given the current behavior is to write:</span></div><div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5"> len(bytestring) == bytestring.count(b'z')</span></div></div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">While I wait for PEP 467, can anyone suggest a better way to write that?</span></div></div></div>