简体   繁体   English

Python代码自省和分析

[英]Python Code Introspection and Analysis

I am trying to write a Python code analyzer, and I am trying to avoid having to parse bare Python text files. 我试图编写一个Python代码分析器,并且试图避免必须解析裸露的Python文本文件。 I was hoping that once the Python compiler/interpreter parses the code there's a way to get to the object code or parse tree from within a running Python program. 我希望一旦Python编译器/解释器解析了代码,便有一种方法可以从运行的Python程序中获取目标代码或解析树。

Is there anyway to do this? 反正有这样做吗?

Thank you 谢谢

asttokenize的组合应该为您想要做的事情提供必要的框架。

您可以看一下Python的抽象语法树

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM