__getitem__ method with tuple argument using Python C-API

Is it possible to define a class c __getitem__that takes an argument tupleusing the Python C-API? Element sq_itemMember tp_as_sequenceelement PyTypeObject has to be ssizeargfunc, so I do not see how to do it. (But I guess NumPy ndarraydoes this.)

+3
source share
1 answer

Yes, use tp_as_mappinginstead.

It mp_subscripttakes it PyObject *, so you can use anything as an index / key.

, , PyObject_GetItem(), ( ) Python o[key]. , tp_as_mapping, , int, tp_as_sequence.

+4

All Articles