creating generators from function

Terry Reedy tjreedy at udel.edu
Wed Dec 8 21:50:58 EST 2004


"Simon Wittber" <simonwittber at gmail.com> wrote in message 
news:4e4a11f8041208171444a6c54 at mail.gmail.com...
> I thought the idiom:
>
> while True:
>    #code which iterates my simulation
>    if condition: break
>
> wat quite normal. This is the style loop I am using.

Yes, quite normal.  This is Python's version of do...until, synthesized 
from while and break.  As most people use the term, this is *not* 
structurally an infinite loop (meaning no break) and also not functionally 
so unless the condition is such that it never breaks either for some or all 
inputs to the function.

> I am trying to allow two modes of concurrency, (threading, and
> pseudo-threading using generators) without having to change my
> application code. If either CPython or Python hacking can provide a
> solution, I'm not sure, but I would be happy with either.

One Python level approach would be to quote the text of the function defs 
that need to switch and then either programmatically edit them or not 
before exec-ing them.  Also messy, but more robust against version and 
implementation changes.

Terry J. Reedy






More information about the Python-list mailing list