quick question about generator.next()

Erik Price erikprice at mac.com
Wed Sep 4 11:42:05 EDT 2002

A quick question about generators:

If I have a generator object, the first value produced by the generator 
object does not actually get produced until the first time I call 
generator_object.next() , correct?

In other words, simply instantiating the generator object doesn't 
"activate" the generator function, rather it just creates it -- only 
when the next() method is called does the generator's internal logic 
"activate", right?

(Where are generator objects getting their next() method from anyway... 
is it implicitly inherited behind the scenes when I use the "yield" 
keyword to turn a function into a generator?)

Thank you,


Erik Price

email: erikprice at mac.com
jabber: erikprice at jabber.org

More information about the Python-list mailing list