How to clear a PyListObject?

筅森魡賤 提交于 2019-12-23 15:05:31

问题


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));


来源:https://stackoverflow.com/questions/23489177/how-to-clear-a-pylistobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!