functors

Tom Plunket tomas at fancy.org
Fri Jul 4 19:25:23 EDT 2003


Jack Diederich wrote:

> I would make countdown dumber, and make the call more explicit
> 
> def countdown(thismany)
>   for (i) in range(thismany):
>     yield False
>   yield True
>   while True:
>     yield False

Hmm.  What's the yield doing here?  I can't find anything on it
in the PQR which has pretty much become my reference of choice
for Python.  I can guess at its function from what I know about
other languages, but ... hmmm.  Doesn't seem like what I want
really, and how would I restart it?  I'm guessing that yield is
akin to return here but the next time the function is called,
program flow resumes at the yield, but...  Yeah, I'm not really
sure how this solves my problem.

> But I'm not sure if this is what you really want, the countdown() 
> keeps going even after it has fired.  Hence the 'While True: 
> yield False'

Right- maybe a similar solution (three return values) that would
allow me to pop the "finished" countdowns off of a stack or
something.

thanks for your help.

-tom!




More information about the Python-list mailing list