我試圖通過從python調用C文件傳遞一個值,然後再從C返回該值到python。如何從C的PyObject類型的函數將C中的值返回給python?
我的問題是如何做到這一點?有沒有可能使用返回Py_BuildValue(a+b)
類的東西?
#include <Python.h>
static PyObject *
hello_world(PyObject *self, PyObject *noargs)
{
int a=5,b=10;
return Py_BuildValue(a+b); //This is Errorus.
}
static PyMethodDef
module_functions[] = {
{ "hello_world", hello_world, METH_NOARGS, "hello world method" },
{ NULL }
};
PyMODINIT_FUNC
inittesty2(void)
{
Py_InitModule("testy2", module_functions);
}