[Python-ideas] Adding str.isascii() ?
Steven D'Aprano
steve at pearwood.info
Tue Jan 30 03:00:23 EST 2018
On Tue, Jan 30, 2018 at 03:12:52PM +1000, Nick Coghlan wrote:
[...]
> So this is partly an optimisation question:
>
> - folks want to avoid allocating a bytes object just to throw it away
> - folks want to avoid running the equivalent of "max(map(ord, text))"
> - folks know that CPython (at least) tracks this kind of info
> internally to manage its own storage allocations
>
> But it's also a readability question: "is_ascii()" and
> "is_UCS2()/is_BMP()" just require knowing what 7-bit ASCII and UCS-2
> (or the basic multilingual plane) *are*, whereas the current ways of
> checking for them require knowing how they *behave*.
Agreed with all of those.
However, given how niche the varieties other than is_ascii() are, I'm
not going to push for them. I use them rarely enough, or on small enough
strings, that doing an O(N) max(string) is not that great a burden. I
can continue using a helper function.
--
Steve
More information about the Python-ideas
mailing list