Iterator / Iteratable confusion
Terry Reedy
tjreedy at udel.edu
Sun Feb 13 17:58:24 EST 2005
"Francis Girard" <francis.girard at free.fr> wrote in message
news:200502131958.27410.francis.girard at free.fr...
> An ""iteratable"" class is a class supporting the __iter__ method which
> should
> return an ""iterator"" instance, that is, an instance of a class
> supporting
> the "next" method.
Not quite right, see below.
> An iteratable, strictly speaking, doesn't have to support the "next"
> method
An iterable with a next method is, usually, an iterator.
> an "iterator" doesn't have to support the "__iter__" method
Yes it does. iter(iterator) is iterator is part of the iterater protocol
for the very reason you noticed...
>(but this breaks the iteration protocol as we will later see).
Iterators are a subgroup of iterables. Being able to say iter(it) without
having to worry about whether 'it' is just an iterable or already an
iterator is one of the nice features of the new iteration design.
Terry J. Reedy
More information about the Python-list
mailing list