STINNER Victor added the comment:
> it is more convenient to just call the method
Calling a Python method in Python is not convenient nor efficient.
For example, PyObject_CallMethod() has to decode a name from UTF-8 and then
needs a lookup into the type dictionary. The list.remove() raises
Serhiy Storchaka added the comment:
PyList_SetSlice() allows to remove an item by index, as in `del a[i]`.
list.remove() searches the item by value and removes the first occurrence. You
can implement it via PySequence_Index() and PyList_SetSlice(), but it is more
convenient to just call the
STINNER Victor added the comment:
I proposed to Hai Shi in his PR to add PyList_Remove() since I was surprised
that the feature is exposed in Python but not at the C level.
> You always can use PyObject_CallMethod(). It is not a method called in tight
> loop for which the overhead of
hai shi added the comment:
> You always can use PyObject_CallMethod(). It is not a method called in tight
> loop for which the overhead of calling method is significant.
Thanks, serhiy. You are right.
To PR19069, it's fine to use `PyList_SetSlice` or `PyObject_CallMethod`.
We don't have the
Serhiy Storchaka added the comment:
You always can use PyObject_CallMethod(). It is not a method called in tight
loop for which the overhead of calling method is significant.
--
nosy: +serhiy.storchaka
___
Python tracker
New submission from hai shi :
Do we need add PyList_Remove() in C level? same thing like list.remove().
As victor comment in:
https://github.com/python/cpython/pull/19069#discussion_r491893466.
--
components: C API
messages: 377566
nosy: shihai1991, vstinner
priority: normal
severity: