Created
February 16, 2013 02:29
-
-
Save felipecruz/4965216 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
import ast | |
# just for convenience | |
Assign = ast.Assign | |
Store = ast.Store | |
Module = ast.Module | |
Name = ast.Name | |
Str = ast.Str | |
# creating an assignment statement -> magic = "loogica" | |
_ast_assignment = Module(body=[Assign(targets=[Name(id="magic", | |
ctx=Store())], | |
value=Str(s="loogica"))]) | |
# ask for help on line stuff generation | |
fixed_ast_assignment = ast.fix_missing_locations(_ast_assignment) | |
# compile ast to code objects | |
code = compile(fixed_ast_assignment, | |
"repl.it", | |
"exec") | |
# executing | |
exec code | |
assert magic == "loogica" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment