Py_BuildValue or PyList_SetItem()
Sheldon
shejo284 at gmail.com
Wed Jan 3 16:16:38 EST 2007
Hi,
I have a function that creates python objects out of C arrays and
returns them to Python. Below is a working example that I later want to
expand to return 12 arrays back to Python. The problem is that when I
print out the values in Python I get undesired reults. See below. Does
anyone know what is going on here?
The array values are good before the conversion.
**************************************
int createPythonObject(void) {
int i,j,k;
PyObject *Rva=PyList_New(12);
for (i = 0; i < 12; i++) {
PyObject *op = PyFloat_FromDouble((double)va[i]);
if (PyList_SetItem(Rva,i,op) !=0) {
fprintf(stderr,"Error in creating python va object\n");
exit(EXIT_FAILURE);
}
Py_DECREF(op);
op = 0;
return Py_BuildValue("N",Rva);
}
Results in Python:
<refcnt 0 at 0x80d885c>, <refcnt 0 at 0x80d885c>, <refcnt 0 at
0x80d885c>, <refcnt 0 at 0x80d885c>, <refcnt 0 at 0x80d885c>, <refcnt 0
at 0x80d885c>, <refcnt 0 at 0x80d885c>, <refcnt 0 at 0x80d885c>,
<refcnt 0 at 0x80d885c>, <refcnt 0 at 0x80d885c>, <refcnt 0 at
0x80d885c>, <refcnt 0 at 0x80d885c>
Any help is appreciated!
/Sheldon
More information about the Python-list
mailing list