Skip to content Skip to sidebar Skip to footer

Passing Array/tuple From Python Back To C++

I am trying to pass a list to python from cpp and taking it back. Initially I tried to pass a single value and get back one value. It worked. Now I am trying to pass the complete a

Solution 1:

From the documentation:

PyObject* PyObject_CallObject(PyObject *callable, PyObject *args) This is the equivalent of the Python expression: callable(*args).

Whereas PyObject_CallFunctionObjArgs is documented as:

PyObject* PyObject_CallFunctionObjArgs(PyObject *callable, ..., NULL) This is the equivalent of the Python expression: callable(arg1, arg2, ...).

So change your call to the following:

PyObject*result= PyObject_CallFunctionObjArgs(pFunc, list, NULL);

(or you could wrap your list inside another list and keep on using CallObject, but this is by far the easier solution)

Post a Comment for "Passing Array/tuple From Python Back To C++"