Maintainability (was Re: Stackless & String-processing)

Skip Montanaro skip at mojam.com
Thu Jul 22 19:22:01 EDT 1999


    Amit> import re
    Amit> from string import *  # Great whenever you're doing string processing
    Amit> re.compile('abc')

Two points.  One, the string module wasn't designed to be imported using
"from string import *".  In my previous message I mentioned the types and
Tkinter modules.  I'm not aware of any others that were explicitly designed
for that.  Two, the bug that placed an object called "re" in the string
module at module scope was fixed several months ago.

    % python
    Python 1.5.2+ (#28, Jun 17 1999, 15:24:35)  [GCC 2.7.2.3] on linux2
    Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
    >>> import string
    >>> dir(string)
    ['_StringType', '__builtins__', '__doc__', '__file__', '__name__',
    '_apply', '_float', '_idmap', '_idmapL', '_int', '_long', 'atof',
    'atof_error', 'atoi', 'atoi_error', 'atol', 'atol_error', 'capitalize',
    'capwords', 'center', 'count', 'digits', 'endswith', 'expandtabs',
    'find', 'hexdigits', 'index', 'index_error', 'join', 'joinfields',
    'letters', 'ljust', 'lower', 'lowercase', 'lstrip', 'maketrans',
    'octdigits', 'replace', 'rfind', 'rindex', 'rjust', 'rstrip', 'split',
    'splitfields', 'startswith', 'strip', 'swapcase', 'translate', 'upper',
    'uppercase', 'whitespace', 'zfill']

Look, Ma! No re!

    Amit> I think the system modules should define all internal variables
    Amit> with a '_' prefix! :-)

Again, the string.re thing was a bug.  Most system modules do follow this
convention.

Skip Montanaro	| http://www.mojam.com/
skip at mojam.com  | http://www.musi-cal.com/~skip/
847-475-3758





More information about the Python-list mailing list