Awkwardness of C API for making tuples

Diez B. Roggisch deetsNOSPAM at web.de
Tue Feb 1 10:52:56 EST 2005


> One of the functions in a C extension I'm writing needs to return a
> tuple of integers, where the length of the tuple is only known at
> runtime. I'm currently doing a loop calling PyInt_FromLong to make the
> integers, then PyTuple_New, and finally a loop calling PyTuple_SET_ITEM
> to set the tuple's items. Whew.
> 
> Does anyone know of a simpler way? I can't use Py_BuildValue because I
> don't know at compile-time how many values there are going to be. And
> there doesn't seem to be a PyTuple_FromArray() function.
> 
> If I'm overlooking something obvious, please clue me in!

If you already know _how_ to create a function like  PyTuple_FromArray() -
why don't you define it yourself and use it?

-- 
Regards,

Diez B. Roggisch



More information about the Python-list mailing list