[Python-Dev] Single- vs. Multi-pass iterability
Guido van Rossum
guido@python.org
Fri, 12 Jul 2002 08:57:14 -0400
> If you put a next method on an iterable you are most probably
> confusing iterators and iterables and not just using the name 'next'
> for some other innocent purpose.
Quite to the contrary. You might have a multi-iterable class that was
defined before the iterator protocol existed, and had a "built-in"
iterator that keeps the iteration state in the object itself (a common
design, e.g. BSD db files have this). This is OK for simple uses.
But with iterators available the class might grow a proper iterator
class that keeps state external from the object. But for backward
compatibility reasons you cannot remove the next() method on the class
itself.
QED: you have a multi-iterable object that has both an __iter__ method
and a next method.
--Guido van Rossum (home page: http://www.python.org/~guido/)