给定AST,是否有一个可用的库来获取源代码? [英] Given an AST, is there a working library for getting the source?

查看:72
本文介绍了给定AST,是否有一个可用的库来获取源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将给定的Python抽象语法树(AST)转换为源代码?

Is there a way to convert a given Python abstract syntax tree (AST) to a source code?

此处是如何使用Python的 ast 模块,特别是 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆