tuple creation in C extensions

Just van Rossum just at letterror.com
Sun Jun 11 04:43:35 EDT 2000


At 11:15 PM +0200 10-06-2000, Peter Schneider-Kamp wrote:
>I have to create a tuple (of two integer values) in a
>C extension. At the moment I use the following (rather
>ugly in my eyes) construction:
>
>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);
>
>where
>PyObject* t;
>long a,b;
>
>Is there "A Better Way(TM)"?

t = Py_BuildValue("(ii)", a, b);

Just






More information about the Python-list mailing list