赞
踩
python抽象语法树
Abstract Syntax Tree is a very strong features in Python. Python AST module allows us to interact with Python code itself and modify it.
抽象语法树是Python中非常强大的功能。 Python AST模块允许我们与Python代码本身进行交互并对其进行修改。
With the Python AST module, we can do a lot of things like modifying Python code and inspect it. The code can be parsed and modified before it is compiled to bytecode
form. It is important to understand that each Abstract Syntax Tree represents each element in our Python code as an object. We will understand this in detail in the coming sections. Let’s try the real code.
使用Python AST模块,我们可以做很多事情,例如修改Python代码并检查它。 在将代码编译为bytecode
形式之前,可以对其进行解析和修改。 重要的是要理解,每个抽象语法树都将Python代码中的每个元素表示为一个对象。 我们将在接下来的部分中详细了解这一点。 让我们尝试真正的代码。
As we mentioned mode in the last script above, there are three modes in which Python code can be compiled. They are:
正如我们在上面的最后一个脚本中提到的mode一样,可以在三种模式下编译Python代码。 他们是:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。