Listing functions in a file IN ORDER

Ian Sparks Ian.Sparks at etrials.com
Tue Jun 29 10:48:22 EDT 2004


I have a python file with a number of functions named with the form doX so :

doTask1
doThing
doOther

The order these are executed in is important and I want them to be executed top-down. They all have the same parameter signature so I'd like to do :

    for name, func in vars(mymodule).items():
        if not name.startswith("do") and callable(func):
            apply(func,my_params)

but the problem is that the return from vars is not ordered the same as in the file. i.e. it could be 

doOther
doTask1
doThing

The low tech solution is to use dir() and re-name the functions to sort alphabetically but perhaps there is a more elegant solution?




More information about the Python-list mailing list