How to get the length of iterable got from PyObject_GetIter()?

I want to get the count of items in iterable got from PyObject_GetIter(). How to do it?

Do you mean that you want to know how many items the iterator will return? That’s not possible.

You can not without consuming it.

You would need to use itertools.tee and iterate through one of them to find length (or a similar solution in C). There is a proposal for ilen Itertools.ilen(iterable), but it would consume the iterator (as it should).