[issue8376] Tutorial offers dangerous advice about iterators: “__iter__() can just return self”

Anders Kaseorg report at bugs.python.org
Thu Jul 22 19:26:57 CEST 2010


Anders Kaseorg <andersk at mit.edu> added the comment:

I don’t think that small change is good enough, if it is still the case that the only provided example is the dangerous one.

It would be easy to clarify the differences between the classes:

>>> rl = test.ReverseList('spam')
>>> [c for c in rl]
['m', 'a', 'p', 's']
>>> [c for c in rl]
['m', 'a', 'p', 's']
>>> ri = iter(rl)
>>> ri
<test.ReverseIterator object at 0x7fa5cbeaec50>
>>> [c for c in ri]
['m', 'a', 'p', 's']
>>> [c for c in ri]
[]

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue8376>
_______________________________________


More information about the Python-bugs-list mailing list