[Python-ideas] Generators are iterators
Guido van Rossum
guido at python.org
Wed Dec 10 22:37:42 CET 2014
On Wed, Dec 10, 2014 at 1:34 PM, Greg Ewing <greg.ewing at canterbury.ac.nz>
> Chris Angelico wrote:
>> Under this proposal, generator functions and iterators would be
>> distinct, but related, concepts. Like the mixing of text and bytes in
>> Python 2, the mixing of generators and iterators has resulted in
>> certain perceived conveniences, but proper separation will make bugs
>> more visible. The distinction is simple: A generator function returns
>> a generator object. The latter is an iterator, having proper __iter__
>> and __next__ methods, while the former has neither and does not follow
>> iterator protocol.
> No, that's still too confused -- all of that was true before as
> well. Generator functions have never been iterators themselves.
> I think Nick has it nailed -- the difference is that code inside
> a generator function implementing a __next__ method will behave
> differently from that inside an ordinary function implementing
> a __next__ method.
That's hardly news though. *Except* for the possibility of raising
StopIteration to end the iteration, the inside of a generator has always
been completely different from the inside of a __next__ method
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas