views:

25

answers:

2

I am writing a native function that will return multiple python objects

PyObject *V = PyList_New(0);
PyObject *E = PyList_New(0);
PyObject *F = PyList_New(0);

return Py_BuildValue("ooo", V, E, F);

This compiles fine, however, when I call it from python, I get an error\

SystemError: bad format char passed to Py_BuildValue

How can this be done correctly?

EDIT: The following works

PyObject *rslt = PyTuple_New(3);
PyTuple_SetItem(rslt, 0, V);
PyTuple_SetItem(rslt, 1, E);
PyTuple_SetItem(rslt, 2, F);
return rslt;

However, I am wondering if there isn't a shorter way to do this.

+3  A: 

I think it wants upper-case O? "OOO", not "ooo".

Ned Batchelder
That still gives the same error message.
celil
Sorry, changed my answer completely. Try again...
Ned Batchelder
Maybe you have also to add parenthesis to make python understand that you want to build a tuple : return Py_BuildValue("(OOO)", V, E, F);
Elenaher
A: 

Use Cython.

return V, E, F
John Machin