On Mon, Nov 24, 2014 at 10:02 AM, Alexander Belopolsky < firstname.lastname@example.org> wrote:
On Mon, Nov 24, 2014 at 12:23 PM, Chris Angelico email@example.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 ...
I think Chris A was overzealous here. The word "generator" is ambiguous; it can refer to either a generator function (a function definition containing at least one "yield") or to the object you obtain by calling a generator function. The latter is definitely an iterator (it has a __next__ method). You can't really call a generator function an iterable (since calling iter() on it raises TypeError) but it's not an iterator either. For the rest see my explanation in response to Mark Shannon in python-dev: http://code.activestate.com/lists/python-dev/133428/