Python dis 模块在 Python 3 中不工作

Python dis module isn't working in Python 3


您好,
我有一个 Python 源代码文件,“test.py”,其内容是 print("Hello World")
当我尝试使用 python3.8 上的集成 py_compile 模块将其编译为字节码时,操作成功,.pyc 文件可能是 运行。
但是,如果我尝试使用 python3.8(带有 python3.8 -m dis {PATH})上的集成 dis 模块读取内容,CPython 会给我这个错误:

Traceback (most recent call last):
 File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
   return _run_code(code, main_globals, None,
 File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
   exec(code, run_globals)
 File "/usr/lib/python3.8/dis.py", line 553, in <module>
   _test()`
 File "/usr/lib/python3.8/dis.py", line 549, in _test
   code = compile(source, args.infile.name, "exec")
ValueError: source code string cannot contain null bytes 

源代码的路径是/home/{USER}/test.py (和Windows下的C:\Users\{USER}\test.py )。
.pyc 文件的路径是/home/{USER}/__pycache__/test.cpython-38.pyc (和Windows 下的C:\Users\{USER}\__pycache__\test.cpython-38.pyc )。

我在这些情况下发现了这个问题:

在WSL和Linux下,我在实验前更新了所有包。

提前感谢您的每一个回复。

如果您查看 dis 模块的源代码:

https://github.com/python/cpython/blob/3.8/Lib/dis.py#L540

您可以看到 -m 调用正在寻找一个 .py 源文件进行编译,然后一步反汇编。它不支持直接给它.pyc。