tuple creation in C extensions
Just van Rossum
just at letterror.com
Wed Jun 14 04:41:20 EDT 2000
At 6:10 PM -0400 13-06-2000, Jeremy Hylton wrote:
>Just van Rossum <just at letterror.com> writes:
>
>> At 11:15 PM +0200 10-06-2000, Peter Schneider-Kamp wrote:
>> >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);
>> >
>> >Is there "A Better Way(TM)"?
>>
>> t = Py_BuildValue("(ii)", a, b);
>>
>> Just
>
>This is a shorter-to-write, slower-to-run version. If you use
>Py_BuildValue, the code has to parse the format string in order to
>build the object. If you are coding in C because you're trying to
>speed up a speed-critical part of your program, the code you posted is
>the better way.
On the other hand, creating tuples is probably not often something one does
inside an inner loop...
Just
More information about the Python-list
mailing list