Skip to content

Instantly share code, notes, and snippets.

@shtaxxx
Created July 23, 2013 21:35
Show Gist options
  • Save shtaxxx/6066388 to your computer and use it in GitHub Desktop.
Save shtaxxx/6066388 to your computer and use it in GitHub Desktop.
#-------------------------------------------------------------------------------
# get an AST of a function defined in globals()
#-------------------------------------------------------------------------------
import ast
import inspect
def getFunctionAst(name):
if name not in globals():
raise NameError("name '%s' is not defined" % name)
func = globals()[name]
source = inspect.getsource(func)
tree = ast.parse(source)
return tree
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment