Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear a PyListObject?

I have a question that how to clear a list that's formed by PyList_Append()? Is there a document about Python/C extension API functions in detail?

like image 622
sophistcxf Avatar asked May 06 '14 08:05

sophistcxf


2 Answers

IIRC you have to use PyList_SetSlice:

PyList_SetSlice(your_list, 0, PyList_Size(your_list), NULL);
like image 63
sloth Avatar answered Nov 11 '22 17:11

sloth


You can use the PySequence_DelSlice function:

# The same as: del L[0:len(L)]
PySequence_DelSlice(L, 0, PySequence_Length(L));
like image 38
vz0 Avatar answered Nov 11 '22 18:11

vz0