Python代码自省与分析

发布于 2024-09-04 15:58:56 字数 139 浏览 3 评论 0 原文

我正在尝试编写一个Python代码分析器,并且试图避免解析裸Python文本文件。我希望一旦 Python 编译器/解释器解析代码,就有一种方法可以从正在运行的 Python 程序中获取目标代码或解析树。

有办法做到这一点吗?

谢谢

I am trying to write a Python code analyzer, and I am trying to avoid having to parse bare Python text files. 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.

Is there anyway to do this?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那请放手 2024-09-11 15:58:56

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

A combination of ast and tokenize should provide the necessary framework for what you want to do.

萌能量女王 2024-09-11 15:58:56

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

You can take a look at Python's abstract syntax trees.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文