Callable generators (PEP 288: Generator Attributes, again)

Aahz aahz at pythoncraft.com
Tue Nov 18 10:05:54 EST 2003


In article <55688f89.0311180211.7ab1bc30 at posting.google.com>,
Francis Avila <francisgavila at yahoo.com> wrote:
>
>A little annoyed one day that I couldn't use the statefulness of
>generators as "resumable functions", [...]

<raised eyebrow>  But generators *are* resumable functions; they just
don't permit injection of new values into their state.  As Michele
pointed out, it's easy enough to wrap a generator in a class if you want
to monitor the changing state of an attribute.

The problem with injecting values is that there's no way to pick them
up; it's a "push" solution rather than a "pull" solution.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote 
programs, then the first woodpecker that came along would destroy civilization.




More information about the Python-list mailing list