Listing functions in a file IN ORDER

Scott David Daniels Scott.Daniels at Acm.Org
Fri Jul 2 16:45:02 CEST 2004

Istvan Albert wrote:

> Ian Sparks wrote:
>> ...python file with functions named doXXX ... order executed important...
 >> I want the system to do code discovery because I'm too dumb to
 >> remember to put things in the list.
> IMHO making the order in which the functions are defined in a module
> define the order in which they will be called upon in another program
> seems to be an awkward solution.
I agree.  Separate the two concerns:

     import sets
     chosen = sets.Set(module.function_list)
     actuals = sets.Set([function for name, function in vars(module)
                 if name.startswith('do') and callable(function))])
     for function in actuals - chosen:
         print >>stderr, 'Warning! forgot about', function.__name__
     # now call them in the specified order.
     for function in function_list:

-Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Python-list mailing list