get list of callable methods

exarkun at exarkun at
Thu Oct 14 20:42:17 CEST 2004

On Thu, 14 Oct 2004 12:46:15 -0500, John Hunter <jdhunter at> wrote:
> What is the best way to get a list of all functions actually defined
> in a module, ignoring those functions that the module may have
> imported but not defined?
> The following gets a list of all the callables, but includes functions
> that some.module imports
> funcs = []
> for o in dir(some.module):
>      if o.startswith('_'): continue
>      p = getattr(some.module, o)
>      if not callable(p): continue
>      funcs.append(p)

  __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.


More information about the Python-list mailing list