1
가정하자 나는 다음 문자열이 있습니다변환 AST 노드
code = """
if 1 == 1 and 2 == 2 and 3 == 3:
test = 1
"""
다음 코드는 AST에 해당 문자열로 변환합니다. 그런 다음
ast.parse(code)
내가 가지고있는 것처럼 나무 : 나는 if 1 == 1 and 2 == 2 and 3 == 3:
내가 그것을 통과 할 수 있습니다 알고있는 문자열로 객체 at.If
를 변환하는 방법이 있는지 알고 싶어
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=[])
자식 노드이지만 너무 복잡해지고 있습니다.
'아이 노드를 통과,'<- 그게 내가 신뢰할 수있는 시도를 제 3 자 도구가 있습니다 – inspectorG4dget
을 수행하는 방법을 알고있는 유일한 방법입니다, 예 ['astor'] (http://astor.readthedocs.io/ko/latest/) – AChampion