Suppose I have the following string:
code = """
if 1 == 1 and 2 == 2 and 3 == 3:
test = 1
"""
The following code converts that string in a AST.
ast.parse(code)
Then I have a tree like:
Module(body=[<_ast.If object at 0x100747358>])
If(test=BoolOp(op=And(), values=[<_ast.Compare object at 0x100747438>, <_ast.Compare object at 0x100747a90>, <_ast.Compare object at 0x100747d68>]), body=[<_ast.Assign object at 0x100747e48>], orelse=[])
I want to know if there is a way to convert the object at.If
into the string if 1 == 1 and 2 == 2 and 3 == 3:
I know it can be done traversing the children node, but it's getting too complicated that way.
traversing the children node,
<- that's the only way I know how to do it – Winnieastor
– Benjamin