Created
May 4, 2018 16:31
-
-
Save JoaoFelipe/bdeb43c754d4c955cbbcaf79d83bd3d7 to your computer and use it in GitHub Desktop.
AST Transformer
This file contains hidden or 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 | |
| import astor | |
| class Hitchhiker(ast.NodeTransformer): | |
| def visit_FunctionDef(self, node): | |
| node.body = [ast.parse('return 42')] | |
| return node | |
| expr=''' | |
| def resposta(): | |
| print ('Alô Mundo') | |
| def outra_resposta(): | |
| return 0 | |
| ''' | |
| p = Hitchhiker().visit(ast.parse(expr)) | |
| print(astor.to_source(p)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment