Skip to content

Instantly share code, notes, and snippets.

@meetmangukiya
Created February 24, 2017 18:21
Show Gist options
  • Save meetmangukiya/4aee7c4b51b205e9badbe30ba3ef8db9 to your computer and use it in GitHub Desktop.
Save meetmangukiya/4aee7c4b51b205e9badbe30ba3ef8db9 to your computer and use it in GitHub Desktop.
List functions and methods of classes in a python file
import ast
import sys
import os
with open(os.path.abspath(sys.argv[-1])) as f:
fc = f.read()
for i in filter(lambda x: isinstance(x, ast.FunctionDef), ast.parse(fc).body):
print(i.name)
print("\n\n")
for i in filter(lambda x: isinstance(x, ast.ClassDef), ast.parse(fc).body):
print(i.name)
for j in filter(lambda x: isinstance(x, ast.FunctionDef), i.body):
print(" " + j.name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment