tuple creation in C extensions

Andrew Kuchling akuchlin at mems-exchange.org
Sat Jun 10 19:16:55 EDT 2000


Peter Schneider-Kamp <petersc at stud.ntnu.no> writes:
> t = PyTuple_New(2);
> PyTuple_SET_ITEM(t,0,PyInt_FromLong(a));
> PyTuple_SET_ITEM(t,1,PyInt_FromLong(b));
> PyErr_SetObject(PyExc_IndexError,t);

Py_BuildValue would simplify the above code:

t = Py_BuildValue("(ll)", a,b);
if (t==NULL) {DECREF other variables, and return NULL}
PyErr_SetObject(PyExc_IndexError, t);

--amk



More information about the Python-list mailing list