How pass array from C to python function

Martin v. Loewis martin at
Thu Sep 19 14:57:27 EDT 2002

"Praveen Patil" <praveen.patil at> writes:

>     mylist = PyList_New(5);
>     for (count=0; count< 5; count++) {
>           myint = PyInt_FromLong(vital_data[count]);
>           PyList_Append(mylist,myint); 
>     }

That is wrong. PyList_Append increases the list size by one, so the
list will have ten elements at the end; 5 of them will be NULL.

Either start with an empty list, or use PyList_SetItem.

>     arglist = Py_BuildValue("O", mylist);
>     ret = PyEval_CallObject(my_callback , arglist);
>     Py_DECREF(arglist);

I recommend to use PyObject_CallFunction here, although your code is

> The information contained in this e-mail is confidential

My reply is confidential, too. Don't read it.


More information about the Python-list mailing list