有人用 Nuitka 为 python 创建了一个 C 模块。(原始 Python 代码不可用,该模块已经编译 - 所以它是一个机器二进制文件。)我想在另一个工具中使用该代码,该工具仅 Python 文件除外。所以我想将 C 代码包含到 Python 中。
更具体地说:到目前为止,我有文件thatmodule.pyi和thatmodule.so. 我可以将它们包含在我当前的 Python 代码中,只需import thatmodule在mymodule.py. 现在我只想要一个 Python 文件mymodule.py。
我目前的想法是将代码从thatmodule.pyi开头复制mymodule.py并转换thatmodule.so为二进制字符串
with open('thatmodule.so', mode='rb') as file:
fileContent = file.read()
... missing ... how to convert fileContent to b'string'...
并将这个二进制字符串放入mymodule.py. 然后我必须从我的 python 模块中执行这个二进制字符串mymodule.py。我怎样才能做到这一点?