A question about generators

Tim Peters tim.one at comcast.net
Wed Mar 20 21:29:38 EST 2002


[Richard J Kuhns]
> That's pretty much what I ended up doing -- I put a "while 1:" loop
> around the rest of the code in the generator, and I test a "reset
> generator" variable after each yield.  If it's set, "continue" the
> while loop. It's kind of nasty-looking, but it seems to work.

Make the generator a method of a class.  Give class instances a "reset
generator" variable.  Give the class a reset() method to set this variable.
Then it's all nice, abstracted, reusable, and self-contained.

a-feature-in-isolation-is-a-feature-doomed-to-misuse-ly y'rs  - tim





More information about the Python-list mailing list