python - 如何将 python 对象传递给 C 扩展并在其中调用其方法?

标签 python python-c-extension

假设我有一个带有方法“m()”的Python对象“o”,我想将其传递为:

PyObject *f(PyObject *self, PyObject *args)
{
  PyObject *o;
  PyArg_ParseTuple(args, "O", &o);
  //o.m();
}

显然最后一个注释行无法编译,我想知道是否有办法可以实现这一点。

最佳答案

关于python - 如何将 python 对象传递给 C 扩展并在其中调用其方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10859456/

相关文章:

python - 如何在 python 中使用 C 扩展来绕过 GIL

Python C API : Using PyEval_EvalCode

linux - Python 的 C 扩展中的 SIGSEGV

python - 元素明智地访问非常大的稀疏矩阵的有效结构(Python/Cython)

python - 在 python 中连接列表和元组的行为不一致

python - 使用 Elasticsearch 后端在 Django Haystack 中启用同义词

c++ - python C API 是否与 C++ 完全兼容?

python - 添加新的 python 类型 : TypeError: can't set attributes of built-in/extension type

python - Bokeh 颜色未出现在悬停工具提示上

python - Numpy 双重求和