Python代码自省与分析
我正在尝试编写一个Python代码分析器,并且试图避免解析裸Python文本文件。我希望一旦 Python 编译器/解释器解析代码,就有一种方法可以从正在运行的 Python 程序中获取目标代码或解析树。
有办法做到这一点吗?
谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ast 和 tokenize 应该为您想要做的事情提供必要的框架。
A combination of ast and tokenize should provide the necessary framework for what you want to do.
你可以看一下Python的抽象语法树。
You can take a look at Python's abstract syntax trees.