Calling a generator multiple times

Courageous jkraska at san.rr.com
Thu Dec 6 17:09:16 EST 2001


>> I'm trying to create a clever way to call a generator multiple
>> times, but the only thing I've been able to come up with is:

I personally think that current generator behavior is all whacked.

The first call to some generator g() should behave like:

	f=g()
	f.next()

Subsequent calls to g() should behave like

	f.next()

The current behavior should be accessible but not the default.
I base this opinion in part upon the way that the generator is
defined. As long as the generator is defined with a signature
which makes it appear as an ordinary function, that's exactly
how it should behave. The semantics of having the function
behave slightly differently upon the second invocation isn't
nearly as surprising as the fact that, under the current
definition, a generator really doesn't behave like a function
at all.

C//




More information about the Python-list mailing list