简体   繁体   English

如何从Python模块中生成代码对象?

[英]How to generate code objects from modules in Python?

I have a .pyc file with no corresponding Python source code. 我有一个.pyc文件,没有相应的Python源代码。 I want to see the disassembly of the module using dis. 我想查看使用dis进行模块的拆卸。 I can import my module just fine with 我可以导入我的模块

import dis
import foo

But to call dis.dis on it, I can't use the module object. 但是要调用dis.dis,我不能使用模块对象。 I need the corresponding code object which backs foo. 我需要支持foo的相应代码对象。 How do I create it? 如何创建它? It seems that the compile builtin can compile strings, classes, methods, and functions, but not files or modules. 似乎内置的编译器可以编译字符串,类,方法和函数,但不能编译文件或模块。

How do I generate this code object given what I have? 给定我该如何生成此代码对象?

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

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