freeze function calls

Santiago Caracol santiago.caracol at gmail.com
Tue Aug 10 14:30:57 CEST 2010


> Python offers an elegant mechanism to calculate values on demand: the
> generator function:
>
> >>> def calculate_answers():
>
> ...     for i in range(100):
> ...             print "calculating answer #%d" % i
> ...             yield i * i
> ...
>

Thanks for pointing this out. I was aware of the yield statement.

My problem is this:

(1) The user submits a query:

---------------------------------
| What is the answer? |
---------------------------------
<Submit>

(2) The web server gives the user N answers and a button saying "More
answers":

. answer 1
. answer 2
. answer 3

<More answers>

At this stage the function that writes html to the user has been
called. The call must be terminated, or else, the user doesn't get any
html. This means that the call of the answer-calculating function,
whether it uses yield or not, is also terminated. This means, when the
user presses the <More answers>-button, the calculation has to start
at the beginning.




More information about the Python-list mailing list