[Python-Dev] other "magic strings" issues

Guido van Rossum guido at python.org
Fri Nov 7 13:59:31 EST 2003

> > Hm, I'd forgotten about ascii_letters.  It would make a beautiful
> > class attribute of str.
> The problem with ascii_letters is that it is not constant.  Depending on
> the startup, it can optionally replace the usual definition with that
> provided by strop.lowercase.

Haven't you got that backwards?  I thought ascii_letters was really a
constant, but letters was modified by setlocale().

> > I *do* think that we don't need string.letters -- the only use for it
> > I've seen is checking if a character is in that string, and
> > c.isletter() is faster.  But if someone has a use case for it that
> > isn't argued away, I'd be okay with seeing it reincarnated as a class
> > attribute of str too.
> I had C coded a patch for a whole group of str.isSomething tests.  The
> only thing that held it up was my not finding time to figure out how to
> exactly the same thing for Unicode objects.  Maybe someone can pick-up
> the patch:
>    www.python.org/sf/562501

I don't have time to investigate the patch; is the existing set of
isXXX() methods not enough?  This seems a separate issue though.

Anyway, I've been nearly convinced that the various constants should
be part of the str class.  But should corresponding constants be added
to the Unicode class???  Some would be very large.  If not, I'm less
convinced that they belong on the str class.

Also, perhaps the locale-dependent variables should perhaps be moved
into the locale module?  That would avoid the Unicode question above,
because the locale module doesn't apply to Unicode.

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list