sophistcxf
sophistcxf

Reputation: 141

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?

Upvotes: 6

Views: 1018

Answers (2)

vz0
vz0

Reputation: 32933

You can use the PySequence_DelSlice function:

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

Upvotes: 6

sloth
sloth

Reputation: 101162

IIRC you have to use PyList_SetSlice:

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

Upvotes: 7

Related Questions