This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: __next__() method in iterators 9.9
Type: Stage: resolved
Components: Documentation Versions: Python 2.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, eryksun, hiba
Priority: normal Keywords:

Created on 2017-06-22 17:19 by hiba, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg296646 - (view) Author: Hiba (hiba) Date: 2017-06-22 17:19
class Reverse:
    """Iterator for looping over a sequence backwards."""
    def __init__(self, data): = data
        self.index = len(data)

    def __iter__(self):
        return self

    def next(self):
        if self.index == 0:
            raise StopIteration
        self.index = self.index - 1

The next() method in the above code snippet(from 9.9 Iterators section in Tutorial is not correctly overridden. It's missing the underscores.
msg296647 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2017-06-22 17:31
Did you try the example in Python 2? Did you click on the "next" link in the preceding paragraph? Please read the following:
       Return the next item from the container....

In Python 3, this method was renamed `__next__`.
Date User Action Args
2022-04-11 14:58:48adminsetgithub: 74923
2017-06-22 17:31:46eryksunsetstatus: open -> closed

nosy: + eryksun
messages: + msg296647

resolution: not a bug
stage: resolved
2017-06-22 17:19:12hibacreate