[Python-Dev] Changes to PEP 327: Decimal data type

Edward Loper edloper at gradient.cis.upenn.edu
Thu Mar 18 12:11:48 EST 2004


> I just did an experiment which involved running the Python
> script appended below over the Library Reference index.
> The results were:  [...]

I ran a similar experiment, but counted the number of *modules* that 
define each type of function (since presumably most modules are 
internally consistent).  The numbers are:

Total modules defining functions: 985
under_score+lowercase : 44%
mixedCase+lowercase   : 22%
lowercase only        : 16%
InitialCaps           : 10%
mixedCase only        : 2%
under_score only      : 2%

So underscore is most common; but mixedCase has a definite presence.

-Edward

p.s., I'm definitely +1 on making a stronger statement in the style 
guide.  Consistency is good.

=========================================================================
# Count function name styles from the Python Library Reference Index.
import re, sys

InitialCaps  = re.compile(r"def\s*_*[A-Z0-9][A-Za-z0-9]*_*\s*\(")
mixedCase    = re.compile(r"def\s*_*[a-z0-9]+[A-Z][A-Za-z0-9]+_*\s*\(")
lowercase    = re.compile(r"def\s*_*[a-z0-9]+_*\s*\(")
under_score  = re.compile(r"def\s*_*[A-Za-z0-9]+_[A-Za-z0-9_]+_*\s*\(")
anydef       = re.compile(r"def\s+.*")

count = {'InitialCaps':0, 'mixedCase only':0, 'lowercase only':0,
          'under_score only':0, 'mixedCase+lowercase':0, 'anydef':0,
          'under_score+lowercase':0}

for file in sys.argv[1:]:
     s = open(file).read()
     if InitialCaps.search(s):
         count['InitialCaps'] += 1
     elif mixedCase.search(s) and lowercase.search(s):
         count['mixedCase+lowercase'] += 1
     elif under_score.search(s) and lowercase.search(s):
         count['under_score+lowercase'] += 1
     elif mixedCase.search(s):
         count['mixedCase only'] += 1
     elif under_score.search(s):
         count['under_score only'] += 1
     elif lowercase.search(s):
         count['lowercase only'] += 1
     else:
         if anydef.search(s):
             print 'huh', anydef.search(s).group()
     if anydef.search(s): count['anydef'] += 1
total = count['anydef']
print 'Total files defining functions:', total
items = count.items()
items.sort(lambda a,b:cmp(b[1],a[1]))
for (key, val) in items:
     print '%-21s : %d%%' % (key, 100*val/total)
=========================================================================




More information about the Python-Dev mailing list