list of all functions defined in the current module

anton muhin antonmuhin.REMOVE.ME.FOR.REAL.MAIL at rambler.ru
Fri Nov 21 07:20:11 EST 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:

<listfunc.py>
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
</lisfunc.py>

<d.py>
import listfunc

for func in listfunc.listfunc():
     print func
</d.py>

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

regards,
anton.





More information about the Python-list mailing list