[capi-sig] Py_BuildValue, Array from C to Python

Guilherme Polo ggpolo at gmail.com
Fri Jan 16 18:31:51 CET 2009


On Fri, Jan 16, 2009 at 2:34 PM, Philipp Heuser <philipp at achtziger.de> wrote:
> Hi all,
>
> I am trying to return an array from C to Python. Since it is of variable
> size,
>
> return Py_BuildValue("[f,f,f]", array[0], array[1], array[2]);
>
> does not help. How do I do that?
>

Create an empty list (PyList_New(0)) and then append  (PyList_Append)
items (PyFloat_FromDouble) as you loop over this array variable. I'm
considering for some reason you don't know the size of this variable,
so it has a sentinel in the end, but if it is not the case you can
create a list with its final size and then use PyList_SetItem.

> Any help is appreciated,
> kind regards
> Philipp


-- 
-- Guilherme H. Polo Goncalves


More information about the capi-sig mailing list