Problems returning data from embedded Python

Cromulent cromulent at justextrememetal.com
Tue Aug 12 20:24:27 EDT 2008


On 2008-08-13 00:50:11 +0100, "Gabriel Genellina" 
<gagsl-py2 at yahoo.com.ar> said:

> En Tue, 12 Aug 2008 19:48:54 -0300, Cromulent  
> <cromulent at justextrememetal.com> escribi�:
> 
>> On 2008-08-12 05:37:53 +0100, "Gabriel Genellina"  
>> <gagsl-py2 at yahoo.com.ar> said:
>> 
>>> <snip>
> Yes, forget about PyArg_ParseTuple. It's intended to parse function  
> arguments. Use the appropiate convert function for each object type. 
> For  integers, use PyInt_AsLong; for floats, PyFloat_AsDouble, and so 
> on.  Something like this (untested):
> 
> // for a column containing float values:
> Py_ssize_t nitems = PyList_Size(the_python_list_of_floats)
> // ...allocate the C array...
> for (Py_ssize_t i=0; i<nitems; i++) {
>    PyObject* item = PyList_GetItem(the_python_list_of_floats, i);
>    your_c_array_of_double[i] = PyFloat_AsDouble(item);
> }

Fantastic! Thanks for your help :). You've got me on the right path now.
-- 
"I disapprove of what you say, but I'll defend to the death your right 
to say it." - Voltaire




More information about the Python-list mailing list