get list of callable methods

John Hunter jdhunter at ace.bsd.uchicago.edu
Thu Oct 14 14:23:43 EDT 2004


    >>   __all__ is the best indicator.  Since not all modules define
    >> it, though, inspect.getsourcefile() is a reasonable fallback to
    >> filter things based on the file of their definition.

Great - this seems to get the job done

import sys, inspect
import matplotlib.matlab

class defined_in:
    def __init__(self, modname):
        self.modname = modname
        
    def __call__(self, o):
        return (inspect.isfunction(o) and
                o.__module__==self.modname and
                not o.__name__.startswith('_'))

modname = 'matplotlib.matlab'
members = inspect.getmembers(sys.modules[modname], defined_in(modname))
for name, o in members:
    print name

JDH



More information about the Python-list mailing list