Re: how to compile this code

2016-11-01 Thread meInvent bbird
>>> class ChangeAddToMultiply(ast.NodeTransformer, ast2.NodeTransformer): ... """Wraps all integers in a call to Integer()""" ... def visit_BinOp(self, node): ... print(dir(node)) ... print(dir(node.left)) ... if isinstance(node.op, ast.Add): ... ast.Call

Re: how to compile this code

2016-11-01 Thread Yann Kaiser
You want to replace the `Add` ast with a `Call` ast rather than just calling your function. Something like: if isinstance(node.op, ast.Add): return ast.Call(some_ast_expression_that_will_evaluate_to_op, [node.left, node.right], []) You'll have to replace some_ast_expression_... to so