[Python-Dev] other "magic strings" issues

Skip Montanaro skip at pobox.com
Sat Nov 8 07:34:07 EST 2003

    Fred> Frankly, that doesn't bother me, especially given that they've
    Fred> always been in the string module.  But I count more than 4
    Fred> constants that should be kept:

    Fred>     ascii_letters
    Fred>     ascii_lowercase
    Fred>     ascii_uppercase
    Fred>     digits
    Fred>     hexdigits
    Fred>     octdigits
    Fred>     whitespace

Don't forget 'punctuation'.  Maybe it should be 'ascii_punctuation', since
I'm sure there are other punctuation characters which would turn up in

    Fred> All of these could reasonably live on both str and unicode if
    Fred> that's not considered pollution.  But if they live in a module,
    Fred> there's no reason not to keep string around for that purpose.

If they are going to be attached to a class, why not to basestring?

    Fred> (I don't object to making them class attributes; I object to creating
    Fred> a new module for them.)

Agreed.  If they stay in a module, I'd prefer they just stay in string.
That creates the minimum amount of churn in people's code.  Anyone who's
been converting to string methods has had to leave all the above constants
alone anyway.


More information about the Python-Dev mailing list