On Fri, Nov 21, 2014 at 9:18 AM, Andrew Barnert < abarnert@yahoo.com.dmarc.invalid> wrote:
Generators are a subtype of iterators. They support the iterator protocol completely, and in the same way as any other iterator. They also support extensions to that protocol--e.g., send(). But they also have a relationship to a generator function or generator expression,
interesting -- I've always called those "generator comprehensions" -- but anyway, -- do they have a special relationship? I can put any iterable in a generator expression: gen_exp = (i for i in [3,4,5,6]) the result is a generator: In [5]: type(gen_exp) Out[5]: generator so I guess you could call that a "special relationship" -- but it looks to me kind of like an alternate constructor. But in any case, you can use a generator created by a generator expression or a generator function the same way you can use a iterable or an iterator class. Then again, the word "generator" itself leads to confusion when speaking
loosely. Maybe it would be clearer if "generator" had no meaning; generator functions return generator iterators.
not sure how that would help -- a generator is a type, and it is created by either calling a generator function or a generator expression. if there is confusion, it's when folks call a generator function a "generator" Anyway, I just went back and read the PEP, and I'm still confused -- would the PEP make generators behave more like iterator classes, or less like them? -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chris.Barker@noaa.gov