case-sensitivity
Alex Martelli
aleax at aleax.it
Fri Nov 14 05:46:04 EST 2003
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:
o
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.
Alex
More information about the Python-list
mailing list