Skip to content

Instantly share code, notes, and snippets.

@bmwant
Created June 2, 2016 10:11
Show Gist options
  • Save bmwant/674d5fe2aedc95ccd7edf5a57ab27c8f to your computer and use it in GitHub Desktop.
Save bmwant/674d5fe2aedc95ccd7edf5a57ab27c8f to your computer and use it in GitHub Desktop.
Inspect usages
import operator
import inspect
def get_module_functions(module, function_prefix=''):
"""
Get all the functions located inside a module which name started with
`function_prefix`
"""
def filter_function(inspected_function):
function_name, function = inspected_function
if (function_name.startswith(function_prefix) and
inspect.getmodule(function) == module):
return True
all_functions = map(operator.itemgetter(1),
filter(filter_function,
inspect.getmembers(module, inspect.isfunction)))
return all_functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment