Skip to content

Instantly share code, notes, and snippets.

@rsgalloway
Created September 24, 2013 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsgalloway/6692410 to your computer and use it in GitHub Desktop.
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.
#!/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