list of all functions defined in the current module

Gerhard Häring gh at ghaering.de
Fri Nov 21 07:14:22 EST 2003


Fernando Rodriguez wrote:
> Hi,
> 
> How can I get the list of all the functions defined in the current module?

If you have

def getfunctions(module):
     import types
     l = []
     for key, value in module.__dict__.items():
         if type(value) is FunctionType:
             l.append(value)
     return l

Then you can call this function with getfunctions(sys.modules[__name__]) 
  to get a list of functions in the current module.

Perhaps you could also use the builtin 'inspect' module for this task.

-- Gerhard






More information about the Python-list mailing list