是否可以将 C 可执行文件与 Python 绑定?

发布于 2025-01-15 22:48:02 字数 329 浏览 0 评论 0原文

最近,我工作的公司已经将其代码库现代化为主要使用 Python。上周,我的任务是研究转换我们用来管理某些 USB 设备的实用程序。我很快发现这个程序是高度专业化的,并且可能不可能转换为 Python(老实说我也不想尝试)。我可以访问该程序的源代码。

该程序在 Linux 上运行,当前编译为可执行文件,而不是共享对象 (.so)。

将 Python 绑定到这个程序是可以合理完成的吗?如果是这样,我已经研究过 ctypes、cffi、cython、pybind11 和编写原始 C 绑定,但我不知道最好的方法是什么。如果没有,也没有重大损失——我只需通过子进程调用该程序并解析其输出。

感谢您抽出时间。

Recently, the company I work for has been modernizing their codebases to mostly Python. Last week, I was tasked with looking into converting a utility program we rely on to manage some USB devices. I was quick to discover this program is highly specialized and is likely impossible to covert to Python (nor do I want to attempt it if I'm being honest). I have access to the source code for this program.

This program runs on Linux and currently compiles to an executable, not a shared object (.so).

Is binding Python to this program something that can be reasonably done? If so, I've already looked into ctypes, cffi, cython, pybind11, and writing raw C bindings, but I am lost as to what the best approach would be. If not, there is no major loss--I'll just have to call the program via subprocess and parse its output.

Thank you for your time.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文