Created
July 28, 2012 22:55
-
-
Save eferro/3195102 to your computer and use it in GitHub Desktop.
Get classes, functions, etc... using instrospection (inspect module)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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