[docs] [issue30738] __next__() method in iterators 9.9
Hiba
report at bugs.python.org
Thu Jun 22 13:19:12 EDT 2017
New submission from Hiba:
class Reverse:
"""Iterator for looping over a sequence backwards."""
def __init__(self, data):
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
return self.data[self.index]
*********************************************
The next() method in the above code snippet(from 9.9 Iterators section in Tutorial is not correctly overridden. It's missing the underscores.
----------
assignee: docs at python
components: Documentation
messages: 296646
nosy: docs at python, hiba
priority: normal
severity: normal
status: open
title: __next__() method in iterators 9.9
versions: Python 2.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30738>
_______________________________________
More information about the docs
mailing list