C API q

Emanuel Landeholm emanuel.landeholm at telia.com
Fri Oct 29 10:00:10 EDT 2004


Alex Martelli wrote:
> Emanuel Landeholm <emanuel.landeholm at telia.com> wrote:
> 
> 
>>Hello!
>>
>>I'm a Py neophyte trying to code an extension module in C. I would like
>>to know how, canonically, to remove a certain PyObject from a PyList,
>>from C. The solution I have come up with so far involves iterating 
>>through the PyList keeping a counter, and then using 
>>PyList_DelItem(counter) on the counter when the iter item == the 
>>PyObject. But this is kind of messy. I'm sure there's a cleaner way to
>>do it?
> 
> 
> You can call the 'remove' method on the list object from C just as you
> could from Python, essentially.  Internally, that does essentially the
> same thing you're doing here, but it does make your own code simpler.

Okay, how do I do that?



More information about the Python-list mailing list