Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zackmdavis/8a7ff3c42a95fb7b01271ed26fe9cee6 to your computer and use it in GitHub Desktop.
Save zackmdavis/8a7ff3c42a95fb7b01271ed26fe9cee6 to your computer and use it in GitHub Desktop.
in [1]: import ast; from ast import *
in [2]: m = ast.parse('def at(): print("@")')
in [3]: m.body[0].name = "@"
in [4]: exec(compile(m, "<string>", 'exec'))
in [5]: globals()['@']
Out[5]: <function __main__.@>
in [6]: globals()['@']()
@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment