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

Wojciech Zabolotny wzab at ise.pw.edu.pl
Thu Dec 9 10:48:18 EST 1999


On Thu, 9 Dec 1999, Wojciech Zabolotny wrote:
> Anyway, what API function should I use to add a new element to the list
> or tuple? I tried to use the PySequence_Concat (like below:)
>  ob = Py_BuildValue("[]");
>  tmp = Py_BuildValue("{s:i,s:i}","as",3,"bc",5);
>  ob = PySequence_Concat(ob,tmp); 
>  ...
> 
> But I get the following error:
> TypeError: illegal argument type for built-in operation

Sorry for replaying my own post, but I've just found the solution.
PyList_Append did the trick for lists. For tuples it seems to be necessary
to use _PyTuple_Resize and PyTuple_SetItem, which is probably much less
efficient :-(. Sorry for unnecessary mess.
-- 
			Wojciech M. Zabolotny
        http://www.ise.pw.edu.pl/~wzab  <--> wzab at ise.pw.edu.pl

http://www.debian.org  Use Linux - an OS without "back doors" inside




More information about the Python-list mailing list