How to add element to the list in C extension module?

Skip Montanaro skip at mojam.com
Thu Dec 9 11:24:48 EST 1999


    Wojciech> Sorry for replaying my own post, but I've just found the
    Wojciech> solution.  PyList_Append did the trick for lists. For tuples
    Wojciech> it seems to be necessary to use _PyTuple_Resize and
    Wojciech> PyTuple_SetItem, which is probably much less efficient

Be careful, there pardner...  There is only one condition where it is safe
to resize a tuple.  The leading underscore indicates that _PyTuple_Resize is
not an external API function.  If your code is the only one holding a
reference to it (it has a reference count of 1), then it is safe to resize
the tuple.  Tuples are supposed to be immutable, so you will run into
problems if you resize it while it's referenced from somewhere else.

Skip Montanaro | http://www.mojam.com/
skip at mojam.com | http://www.musi-cal.com/
847-971-7098   | Python: Programming the way Guido indented...





More information about the Python-list mailing list