pre-PEP: The create statement

Michele Simionato michele.simionato at gmail.com
Thu Apr 6 09:50:31 EDT 2006


Kay Schluehr wrote:
> Steven Bethard wrote:
>
> > Python-Version: 2.6
>
> Have you a rough estimation how many modules will be broken when
> "create" is introduced as a keyword?

This is a very relevant question. I would expect the new keyword would
break lots
of modules. However measuring is better than speculating.

$ echo count_name.py
"""
Count the occurrences of a name in a Python script. For instance:

$ find /usr/lib/python2.4 -name \*.py  | xargs python2.4 count_name.py
create
"""

import sys, tokenize, token

def count_name(name, script):
    "Count the occurrences of a Python name in a script"
    counter = 0
    for tok_code, tok_value, (srow, scol), (erow, ecol), line in \
            tokenize.generate_tokens(file(script).readline):
        if tok_code == token.NAME and tok_value == name:
            counter += 1
            print 'line %s: %s' %(srow, line),
    if counter: print '*** %s ***\n' % script
    return counter

if __name__ == '__main__':
    name = sys.argv[1]
    scripts = sys.argv[2:]
    total = sum(count_name(name, script) for script in scripts)
    print 'Found %d occurrences of %r' % (total, name)

Here is the output on my box:

line 132:     def __init__(self, filename, dbhome, create=0,
truncate=0, mode=0600,
line 140:         if create:
*** /usr/lib/python2.4/bsddb/dbtables.py ***

line 312:     def get_finalized_command (self, command, create=1):
line 318:         cmd_obj = self.distribution.get_command_obj(command,
create)
*** /usr/lib/python2.4/distutils/cmd.py ***

line 828:     def get_command_obj (self, command, create=1):
line 835:         if not cmd_obj and create:
*** /usr/lib/python2.4/distutils/dist.py ***

line 379:     def create(self, mailbox):
*** /usr/lib/python2.4/imaplib.py ***

line 1569:         self.tk = _tkinter.create(screenName, baseName,
className, interactive, wantobjects, useTk, sync, use)
*** /usr/lib/python2.4/lib-tk/Tkinter.py ***




More information about the Python-list mailing list