list of all functions defined in the current module

anton muhin antonmuhin.REMOVE.ME.FOR.REAL.MAIL at
Fri Nov 21 13:20:11 CET 2003

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

Here's what I managed to do:

import inspect

def listfunc():
     me = __import__(inspect.getmodulename(__file__))
     for name in dir(me):
         obj = getattr(me, name)
         if inspect.isfunction(obj):
             yield obj

def foo(): pass

def bar(): pass

import listfunc

for func in listfunc.listfunc():
     print func

It prints:
<function bar at 0x008ECAF0>
<function foo at 0x008ECAB0>
<function listfunc at 0x008F3430>


More information about the Python-list mailing list