help with Python C-API, tuple object

fabian.conrad at gmail.com fabian.conrad at gmail.com
Sat May 12 00:11:06 EDT 2007


Hi,
sorry for the rather basic question but I've searched everywhere and
don't find an answer.
I want to call PyObject_CallObject from the Python C-API and pass a
tuple I've created from a C-array

How can I pass the tuple as an object rather then having to declare
the python function with the number of arguments equal to the no of
elements in the tuple?

Example:
C-Code fragment:
PyObject *pArgs =  PyTuple_New(3);
//module is imported and function object is build and checked
        for (i=0; i<3; i++){
	     pInt = PyInt_FromLong(i);
	    error = PyTuple_SetItem(pArgs, i, pInt);
}
pValue=PyObject_CallObject(pFunc, pArgs);//returns NULL!!!

Python Script:
def length(a):
    length = len(a)
    return length




More information about the Python-list mailing list