[Python-Dev] String module
Wed, 29 May 2002 18:51:02 -0400
From: "Alex Martelli" <firstname.lastname@example.org>
> > strings. That way, we can get O(1) behavior instead of O(n) behavior
> > code like: if c in str.printable: c='*'. If someone needs to know
> > contents, they can run str.printable.keys(). Also, because the
> > is mutable, someone can (at runtime) expand or contract the definitions:
> > str.whitespace.append('_').
> append would of course not work on a dictionary, but the prospect of
> allowing easy mutation of fundamental built-ins is quite negative in
> goes against the grain of the language. A read-only dictionary might be
I like the read-only dictionary better than the boolean test methods. It
minimizes the effort in upgrading existing code of the form:
for c in string.lowercase:
if c in string.lowercase:
I can global search/replace string.lowercase with str.lower in dictionary
form and everything will run fine (and faster too).
Also, I like the mapping because provides a way to see the membership. With
the string form or the mapping form, it's easy to find-out exactly what is
defined as whitespace. If there is a C coded boolean test, I have to filter
the whole alphabet or look it up in the docs.
If we can get some agreement that this is the way to go, I can work with the
OP on a revised patch so we get the string module silently deprecated.