Created
July 14, 2015 20:31
-
-
Save kragen/ae68f88099b4d3e8f703 to your computer and use it in GitHub Desktop.
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
: user@debian:~/devel/dev3; cat modtree.py | |
#!/usr/bin/python | |
import sys | |
def main((_, modname,)): | |
showed = set() | |
for depth, name, filename in mod_tree(__import__(modname)): | |
print ' ' * 4 * depth, name, filename if name not in showed else '' | |
showed.add(name) | |
def mod_tree(mod, seen=set()): | |
yield 0, mod.__name__, getattr(mod, '__file__', None) | |
if mod not in seen: | |
seen.add(mod) | |
for item in ((depth+1, name, filename) | |
for submod in (getattr(mod, dep) for dep in dir(mod)) | |
if type(submod) is type(mod) | |
for depth, name, filename in mod_tree(submod, seen)): | |
yield item | |
if __name__ == '__main__': | |
main(sys.argv) | |
: user@debian:~/devel/dev3; ./modtree.py email.parser | |
email /usr/lib/python2.7/email/__init__.pyc | |
email._parseaddr /usr/lib/python2.7/email/_parseaddr.pyc | |
calendar /usr/lib/python2.7/calendar.pyc | |
locale /usr/lib/python2.7/locale.pyc | |
encodings /usr/lib/python2.7/encodings/__init__.pyc | |
__builtin__ None | |
encodings.aliases /usr/lib/python2.7/encodings/aliases.pyc | |
codecs /usr/lib/python2.7/codecs.pyc | |
__builtin__ | |
sys None | |
encodings.utf_8 /usr/lib/python2.7/encodings/utf_8.pyc | |
codecs | |
functools /usr/lib/python2.7/functools.pyc | |
operator None | |
re /usr/lib/python2.7/re.pyc | |
copy_reg /usr/lib/python2.7/copy_reg.pyc | |
sre_compile /usr/lib/python2.7/sre_compile.pyc | |
_sre None | |
sre_parse /usr/lib/python2.7/sre_parse.pyc | |
sys | |
sys | |
sre_parse | |
sys | |
sys | |
datetime /usr/lib/python2.7/lib-dynload/datetime.so | |
sys | |
time None | |
email.base64mime /usr/lib/python2.7/email/base64mime.pyc | |
email.charset /usr/lib/python2.7/email/charset.pyc | |
codecs | |
email.errors /usr/lib/python2.7/email/errors.pyc | |
email.encoders /usr/lib/python2.7/email/encoders.pyc | |
base64 /usr/lib/python2.7/base64.pyc | |
binascii None | |
re | |
struct /usr/lib/python2.7/struct.pyc | |
email.errors | |
email.feedparser /usr/lib/python2.7/email/feedparser.pyc | |
email.errors | |
email.message /usr/lib/python2.7/email/message.pyc | |
binascii | |
email.errors | |
re | |
email.utils /usr/lib/python2.7/email/utils.pyc | |
base64 | |
os /usr/lib/python2.7/os.pyc | |
UserDict /usr/lib/python2.7/UserDict.pyc | |
_abcoll /usr/lib/python2.7/_abcoll.pyc | |
sys | |
copy_reg | |
errno None | |
posixpath /usr/lib/python2.7/posixpath.pyc | |
genericpath /usr/lib/python2.7/genericpath.pyc | |
os | |
stat /usr/lib/python2.7/stat.pyc | |
os | |
stat | |
sys | |
warnings /usr/lib/python2.7/warnings.pyc | |
linecache /usr/lib/python2.7/linecache.pyc | |
os | |
sys | |
sys | |
types /usr/lib/python2.7/types.pyc | |
sys | |
random /usr/lib/python2.7/random.pyc | |
hashlib /usr/lib/python2.7/hashlib.pyc | |
_hashlib /usr/lib/python2.7/lib-dynload/_hashlib.so | |
_random None | |
re | |
socket /usr/lib/python2.7/socket.pyc | |
_socket None | |
_ssl /usr/lib/python2.7/lib-dynload/_ssl.so | |
errno | |
os | |
sys | |
warnings | |
time | |
urllib /usr/lib/python2.7/urllib.pyc | |
base64 | |
os | |
socket | |
ssl /usr/lib/python2.7/ssl.pyc | |
_ssl | |
base64 | |
errno | |
textwrap /usr/lib/python2.7/textwrap.pyc | |
re | |
string /usr/lib/python2.7/string.pyc | |
re | |
string | |
sys | |
time | |
warnings | |
uu /usr/lib/python2.7/uu.pyc | |
binascii | |
os | |
sys | |
warnings | |
re | |
email.iterators /usr/lib/python2.7/email/iterators.pyc | |
sys | |
email.message | |
email.mime /usr/lib/python2.7/email/mime/__init__.pyc | |
email.parser /usr/lib/python2.7/email/parser.pyc | |
warnings | |
email.quoprimime /usr/lib/python2.7/email/quoprimime.pyc | |
re | |
sys | |
email.utils | |
: user@debian:~/devel/dev3; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment