Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get classes, functions, etc... using instrospection (inspect module)
#!/usr/bin/python
import sys
import inspect
import os.path
import os
def get_symbols_from_module(python_module, filter_func):
members = inspect.getmembers(python_module)
return dict([[name,symbol] for name,symbol in members
if filter_func(symbol)])
def main():
# Obtain a map whith all the classes defined in the
# standard os module
print get_symbols_from_module(os, inspect.isclass)
# Obtain a map with all the functions defined in the
# standard sys module
print get_symbols_from_module(sys, inspect.isfunction)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.