[Python-ideas] Generators are iterators
greg.ewing at canterbury.ac.nz
Wed Dec 10 22:34:03 CET 2014
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.
More information about the Python-ideas