Created
September 24, 2013 22:47
-
-
Save rsgalloway/6692410 to your computer and use it in GitHub Desktop.
Simple utility to parse the __doc__, __name__ and __author__ values from a Python module.
This file contains hidden or 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/env python | |
""" | |
Simple utility to parse the __doc__, __name__ and __author__ values from | |
a Python module. | |
""" | |
import sys | |
import ast | |
m = ast.parse(''.join(open(sys.argv[1]))) | |
doc = ast.get_docstring(m) | |
assigns = [node for node in m.body if type(node) == ast.Assign] | |
names = [a.value.s for a in assigns if a.targets[0].id == '__name__'] | |
authors = [a.value.s for a in assigns if a.targets[0].id == '__author__'] | |
print doc, names, authors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment