How to clear a PyListObject?

2019-06-28 08:17发布

问题:

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

回答1:

IIRC you have to use PyList_SetSlice:

PyList_SetSlice(your_list, 0, PyList_Size(your_list), NULL);


回答2:

You can use the PySequence_DelSlice function:

# The same as: del L[0:len(L)]
PySequence_DelSlice(L, 0, PySequence_Length(L));