Skip to content

Instantly share code, notes, and snippets.

@csaez
Created November 7, 2017 06:38
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 csaez/7d14cde642eb11b3d3c8d367fc96b9f1 to your computer and use it in GitHub Desktop.
Save csaez/7d14cde642eb11b3d3c8d367fc96b9f1 to your computer and use it in GitHub Desktop.
Command line to extract __all__ from python files
#!/usr/bin/python
import imp
import sys
def main(filepath):
module = imp.load_source('foo', filepath)
entities = [repr(x) for x in dir(module) if not x.startswith('__')]
if entities:
text = ', '.join(entities)
return '__all__ = [{0}]'.format(text)
if __name__ == "__main__":
if len(sys.argv) > 1:
for f in sys.argv[1:]:
print main(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment