[Python-ideas] Adding str.isascii() ?

Guido van Rossum guido at python.org
Fri Jan 26 21:38:42 EST 2018

IMO the special status for isascii() matches the special status of ASCII as
encoding (yeah, I know, it's not the default encoding anywhere, but it
still comes up regularly in standards and as common subset of other

Should you wish to check for compatibility with other ranges IMO some
expression involving max(<the_string>) should cut it.

(FWIW there should be a special place in hell for those people who say
"ASCII" when they mean "Latin-1".)

On Fri, Jan 26, 2018 at 5:27 PM, Steven D'Aprano <steve at pearwood.info>

> On Fri, Jan 26, 2018 at 02:37:14PM +0100, Victor Stinner wrote:
> > 2018-01-26 13:39 GMT+01:00 Steven D'Aprano <steve at pearwood.info>:
> > > I have no objection to isascii, but I don't think it goes far enough.
> > > Sometimes I want to know whether a string is compatible with Latin-1 or
> > > UCS-2 as well as ASCII. For that, I used a function that exposes the
> > > size of code points in bits:
> >
> > Really? I never required such check in practice. Would you mind to
> > elaborate your use case?
> tcl/tk and Javascript only support UCS-2 (16 bit) Unicode strings.
> Dealing with the Supplementary Unicode Planes have the same problems
> that older "narrow" builds of Python sufferred from: single code points
> were counted as len(2) instead of len(1), slicing could be wrong, etc.
> There are still many applications which assume Latin-1 data. For
> instance, I use a media player which displays mojibake when passed
> anything outside of Latin-1.
> Sometimes it is useful to know in advance when text you pass to another
> application is going to run into problems because of the other
> application's limitations.
> --
> Steve
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/

--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180126/68e2cc44/attachment-0001.html>

More information about the Python-ideas mailing list