[Python-Dev] Re: Single- vs. Multi-pass iterability
François Pinard
pinard@iro.umontreal.ca
09 Jul 2002 17:54:40 -0400
[Oren Tirosh]
> [François Pinard]
> > However, as the iterator maintains its own progressive state, I do not see
> > the intent and purpose of the iterator having an `__iter__' method itself.
> As far as I can tell this was done so that for could iterate over both
> iterables and iterators.
That is, that an iterator is always itself an iterable. I guess the real
question is: could we have the guarantee that if an iterable returns an
iterator through the iterable's __iter__, the iterator's __iter__ method
will never be called from looping over the iterable? If we do not have
that guarantee, then, when (and why) will the iterator's __iter__ be called?
I did not find an answer to these questions neither from the Reference Manual
nor the PEP, yet I confess that the exposition of the C API might hold an
answer I could not understand. Could it be explained without referring to C?
--
François Pinard http://www.iro.umontreal.ca/~pinard