Created
July 23, 2013 21:35
-
-
Save shtaxxx/6066388 to your computer and use it in GitHub Desktop.
This file contains 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
#------------------------------------------------------------------------------- | |
# 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