给定AST,是否有一个可用的库来获取源代码? [英] Given an AST, is there a working library for getting the source?
问题描述
是否可以将给定的Python抽象语法树(AST)转换为源代码?
Is there a way to convert a given Python abstract syntax tree (AST) to a source code?
此处是如何使用Python的 ast $ c的好例子$ c>模块,特别是
NodeTransformer
。我一直在寻找将产生的AST转换回源代码的方法,以便可以直观地检查更改。
Here is a good example of how to use Python's ast
module, specifically a NodeTransformer
. I was looking for a way to convert the resulting AST back to source, so the changes can be inspected visually.
推荐答案
Python源代码树包含以下内容的实现:Demo / parser目录中的unparse.py: https://github.com/python/cpython/blob/master/Tools/parser/unparse.py
The Python source tree contains an implementation of this: unparse.py in the Demo/parser directory: https://github.com/python/cpython/blob/master/Tools/parser/unparse.py
这篇关于给定AST,是否有一个可用的库来获取源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!