coroutines?
David Eppstein
eppstein at ics.uci.edu
Fri Jun 15 15:00:45 EDT 2001
I'm working on writing a prog (using W windowing in MacPython) that handles
a list of items. For each item, it needs to open a dialog and gather some
user information. So, the natural way to structure it is
for each item in list: handle dialog
I guess it would be possible to run that way in a separate application, by
setting up a new instance of W every time, but that wouldn't allow me to
reuse windows and wouldn't work well when running interactively in the IDE.
Instead, what it looks like I would end up doing is to have a queue of list
items sitting around somewhere, and (whenever the ok button of my dialog is
pressed) go on to the next item and reset all the windowing objects. Which
would work, but is logically upside-down.
What I really want is coroutines. That way I could have my outer structure
be
for each item in list: set up dialog then coreturn to W
while the "ok" button of the dialog would simply coreturn to this loop.
The last time I was actually able to write a coroutine was 15 years ago
when I was programming assembler. Most modern languages don't have them.
Threads are not really an appropriate substitute. But I'm new to Python,
and maybe it has something the other languages don't have. Is there a
clean way to do coroutines in Python?
--
David Eppstein UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/
More information about the Python-list
mailing list