[Python-Dev] other "magic strings" issues

Guido van Rossum guido at python.org
Fri Nov 7 18:17:17 EST 2003


>  > In the end it would be a module containing 4 constants and one
>  > function.  I'd rather consolidate all that elsewhere.
> 
> Frankly, that doesn't bother me, especially given that they've always
> been in the string module.  But I count more than 4 constants that
> should be kept:
> 
>     ascii_letters
>     ascii_lowercase
>     ascii_uppercase
>     digits
>     hexdigits
>     octdigits
>     whitespace
> 
> All of these could reasonably live on both str and unicode if that's
> not considered pollution.  But if they live in a module, there's no
> reason not to keep string around for that purpose.
> 
> (I don't object to making them class attributes; I object to creating
> a new module for them.)

Ah, we agree about this then.

I do think that keeping the string module around without all the
functions it historically contained would be a mistake, confusing
folks.  This error is pretty clear:

   >>> import string
  Traceback (most recent call last):
    File "<stdin>", line 1, in ?
  ImportError: No module named string
  >>> 

But this one is much more mystifying:

  >>> import string
  >>> print string.join(["a", "b"], ".")
  Traceback (most recent call last):
    File "<stdin>", line 1, in ?
  AttributeError: 'module' object has no attribute 'join'
  >>> 

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



More information about the Python-Dev mailing list