On Tue, Nov 25, 2014 at 5:02 AM, Alexander Belopolsky alexander.belopolsky@gmail.com wrote:
On Mon, Nov 24, 2014 at 12:23 PM, Chris Angelico rosuav@gmail.com wrote:
Well, there is probably more to be said about this - along the lines of *why* generators ought to be more like iterators. (They're iterables, not iterators.)
If generators are not iterators, how do you explain this?
import collections def g():
... yield 42 ...
isinstance(g(), collections.Iterator)
True
My apologies. As Guido said, "generator" is ambiguous; though I was inaccurate as well. A generator *object* is, as you show above, an iterator; a generator *function* is not actually iterable, but it is an iterator factory. An iterator class is also an iterator factory.
ChrisA