python - 为 python 模块创建 golang 绑定(bind)

标签 python go binding cpython

我想为现有的(第三方)Python 模块编写 golang 绑定(bind)。
目的是我想使用 Python 模块在 Golang 中提供的 API。
我已经找到了 Python 的 C API 的 golang 绑定(bind)(go-python3 用于 py3 和 go-python 用于 py2),但我仍然没有弄清楚如何将相对复杂的 Python 模块转换为 Golang(即如何处理在 python 中寻找不安全的输入和返回等)。
什么是好方法?该领域是否有任何预先存在的工具? Python代码的Golang绑定(bind)有什么好的例子吗? (我找不到很多 tbh)。

最佳答案

I want to use the API that the Python module provides in Golang.


最近在 Python and Go : Part I - gRPC 的“Miki Tebeka”中详细介绍了从 Go 调用 Python。 .
您可以在 ardanlabs/python-go/grpc 中查看示例
但是,如 their next two articles 所示, 你也可以:
  • 将 Go 代码编译到共享库并从 Python 交互式 shell 中使用它。
  • 使用隐藏使用共享库的低级细节的 Python 模块,然后将此代码打包为 Python 包。

  • https://www.ardanlabs.com/images/goinggo/124_figure1.png
    完整示例: ardanlabs/python-go/pyext .

    关于python - 为 python 模块创建 golang 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63510031/

    相关文章:

    python - NumPy 中 ndim 的真正作用是什么?

    python - type(1) 是否等同于 type.__call__(1)?

    python - 我想循环播放音乐

    go - 无法将 time.Now() 转换为字符串

    go - 如何更改水牛路由器记录的消息的优先级

    ios - 无法加载 wikitude monotouch 绑定(bind)

    WPF TextBlock.TextTrimming 不适用于自动调整大小的 ColumnDefinition

    Python检查变量是否在列表中重复

    arrays - 戈朗 : Could not understand how below code is executing

    .net - XAML 正在使用先前的绑定(bind)调用 get