[Python-ideas] Adding str.isascii() ?
storchaka at gmail.com
Wed Jan 31 07:17:03 EST 2018
31.01.18 13:18, INADA Naoki пише:
> Yes. But .isascii() will be match faster than try ...
> .encode('ascii') ... except UnicodeEncodeError
> on most Python implementations.
In this case this doesn't matter since this is an exceptional case, and
in any case an exception is raised for non-ascii string.
But you are true that str.isascii() can be faster than str.encode(), and
encoding is not required for converting to int.
>> Other possibility -- adding support of the boolean argument in str.isdigit()
>> and similar predicates that switch them to the ASCII-only mode. Such option
>> will be very useful for the str.strip(), str.split() and str.splilines()
>> methods. Currently they split using all Unicode whitespaces and line
>> separators, but there is a need to split only on ASCII whitespaces and line
>> separators CR, LF and CRLF. In case of str.strip() and str.split() you can
>> just pass the string of whitespace characters, but there is no such option
>> for str.splilines().
> It sounds good idea. Maybe, keyword only argument `ascii=False`?
There is an issue for str.splilines() (don't remember the number). The
main problem was that I was not sure about an obvious argument name.
> But if revert adding str.isascii() from Python 3.7, same keyword-only
> argument should be
> added to int(), float(), decimal.Decimal(), fractions.Fraction(),
> etc... It's bit hard.
Ah, it is already committed. Then I think it is too later to revert
this. I had doubts about this feature and were -0 for adding it (until
we discuss it more), but since it is added I don't see much benefit from
More information about the Python-ideas