Ron Adam radam2 at
Fri Nov 14 13:24:54 CET 2003

On Fri, 14 Nov 2003 10:46:04 GMT, Alex Martelli <aleax at>

>Ron Adam wrote:
>    ...
>> I wonder how difficult it would be to write a program that searches
>> the library and counts the number of instances like spelling with
>> differing case are used?
>You mean "used within the same namespace"?  Not too hard, since the
>key test is nothing more than something like:
>so basically it boils down to finding all namespaces of interest.
>Easy for modules, easy for classes, NOT easy for class-instances
>as you'd really have to create the instances to check for such
>cases as, e.g.:
>class Foo(object):
>    def blab(self): return self.BLAB
>    def __init__(self, BLAB): self.BLAB = BLAB
>So here's a q&d check for such module-level conflicts I just
>cobbled together (avoiding obsolete modules):
>import sys, glob, os.path, sets
>avoid = sets.Set('''
>    FCNTL posixfile pre regsub statcache TERMIOS this tzparse xmllib
>    '''.split())
>for where in sys.path:
>    modules = glob.glob(os.path.join(where, '*.py'))
>    modnams = [os.path.basename(m)[:-3] for m in modules]
>    for m in modnams:
>        if m in avoid: continue
>        try: modobj = __import__(m)
>        except ImportError: continue
>        dd = dir(modobj)
>        lowdd = [ n.lower() for n in dd ]
>        slowd = sets.Set(lowdd)
>        if len(dd) != len(slowd):
>            print '%s:'%m,
>            n = 0
>            for d in dd:
>                if lowdd.count(d.lower()) != 1:
>                    print d,
>                    n += 1
>            print
>The hits in the top-level of the standard libraries are:
>binhex: BinHex HexBin binhex hexbin
>copy: Error error
>popen2: Popen3 Popen4 popen3 popen4
>pydoc: Doc doc
>random: Random random
>repr: Repr repr
>sre_parse: SUBPATTERN SubPattern
>sre: TEMPLATE template
>tarfile: VERSION version
>threading: _VERBOSE _Verbose
>tokenize: COMMENT Comment NAME NUMBER Name Number STRING String string
>xmlrpclib: Boolean boolean
>there are more in lib-tk and Numeric, but not everybody will be
>interested in those, I guess.

Thanks Alex,  I'll play around with this a bit.

It looks like the number of them is low enough to build in exceptions
for already existing instances,  and it may be possible to have a
policy of avoiding it in the future.

In any case,  this is helping understand how python works.  I'm
finding it very interesting that so much of python is programmed in

_Ron Adam

More information about the Python-list mailing list