Awkwardness of C API for making tuples

Dave Opstad dave.opstad at monotypeimaging.com
Tue Feb 1 10:28:17 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!

Thanks,
Dave Opstad



More information about the Python-list mailing list