Skip to content

Instantly share code, notes, and snippets.

@stuartmyles
Created August 9, 2015 22:03
Show Gist options
  • Save stuartmyles/2d20566074709a5a80bc to your computer and use it in GitHub Desktop.
Save stuartmyles/2d20566074709a5a80bc to your computer and use it in GitHub Desktop.
Python ast code to figure out how to call an instance object method and pass in a parameter, i.e. equivalent to result = self._baz(theResult)"
import ast
# ast code to figure out how to call an instance object method and pass in a parameter, i.e. equivalent to
# result = self._baz(theResult)"
class Greeter:
def _baz(self, theStr):
return theStr
def baz(self, theResult):
theTree = ast.parse("result = self._baz(theResult)")
print(ast.dump(theTree))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment