如何使用 Jython 将 .pyc 文件反编译为 .py

How to decompile .pyc file to .py using Jython

我有一个 python 组件,它独立工作并作为 windows 服务运行。这个 python 的一个特定文件执行我需要使用我的 java class 调用的特定工作。因为是生产环境,所以没有提供.py文件。要从 .py 文件调用方法 "run",我使用以下代码:

PyInterpreter py = new PyInterpreter();

py.execfile("C:\Users\narendrar\Desktop\hello.py");

PyInstance hello = py.createClass("Hello", "None");
    hello.invoke("run");

我想执行类似的操作,但使用的是已编译的 python 文件。

正如您在有关 modules 的 jython 文档中看到的那样,jython import 不一定与 Java 包有关

换句话说:您也应该能够 import/require python 模块,从而可以依赖您的 pyc 文件!

(请记住:您可以导入 pyc 文件,只有比 pyc 更新 的 .py 文件才会被引入 - 请参阅 here