10 There are only a couple of functions specifically for working with iterators.
13 .. cfunction:: int PyIter_Check(PyObject *o)
15 Return true if the object *o* supports the iterator protocol.
18 .. cfunction:: PyObject* PyIter_Next(PyObject *o)
20 Return the next value from the iteration *o*. If the object is an iterator,
21 this retrieves the next value from the iteration, and returns *NULL* with no
22 exception set if there are no remaining items. If the object is not an
23 iterator, :exc:`TypeError` is raised, or if there is an error in retrieving the
24 item, returns *NULL* and passes along the exception.
26 To write a loop which iterates over an iterator, the C code should look
29 PyObject *iterator = PyObject_GetIter(obj);
32 if (iterator == NULL) {
36 while (item = PyIter_Next(iterator)) {
37 /* do something with item */
39 /* release reference when done */
45 if (PyErr_Occurred()) {
49 /* continue doing useful work */