Server IP : 51.89.169.208 / Your IP : 18.222.227.24 Web Server : Apache System : Linux ns3209505.ip-198-244-202.eu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Tue Nov 5 04:50:16 EST 2024 x86_64 User : yellowleaf ( 1019) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /proc/self/root/usr/share/doc/python3-docs/html/_sources/c-api/ |
Upload File : |
.. highlightlang:: c .. _iterator: Iterator Protocol ================= There are two functions specifically for working with iterators. .. c:function:: int PyIter_Check(PyObject *o) Return true if the object *o* supports the iterator protocol. .. c:function:: PyObject* PyIter_Next(PyObject *o) Return the next value from the iteration *o*. The object must be an iterator (it is up to the caller to check this). If there are no remaining values, returns *NULL* with no exception set. If an error occurs while retrieving the item, returns *NULL* and passes along the exception. To write a loop which iterates over an iterator, the C code should look something like this:: PyObject *iterator = PyObject_GetIter(obj); PyObject *item; if (iterator == NULL) { /* propagate error */ } while (item = PyIter_Next(iterator)) { /* do something with item */ ... /* release reference when done */ Py_DECREF(item); } Py_DECREF(iterator); if (PyErr_Occurred()) { /* propagate error */ } else { /* continue doing useful work */ }