Use inspect module:
def is_function_local(object): return isinstance(object, types.FunctionType) and object.__module__ == __name__ import sys print inspect.getmembers(sys.modules[__name__], predicate=is_function_local)
Example:
import inspect import types from os.path import join def square(x): return x*x def cube(x): return x**3 def is_local(object): return isinstance(object, types.FunctionType) and object.__module__ == __name__ import sys print [name for name, value in inspect.getmembers(sys.modules[__name__], predicate=is_local)]
prints:
['cube', 'is_local', 'square']
See: no join function imported from os.path .
is_local here, as it is the current module. You can transfer it to another module or exclude it manually or define it instead of lambda (as suggested by @BartoszKP).
source share