question about generators
eppstein at ics.uci.edu
Tue Aug 20 07:05:15 CEST 2002
In article <3D618866.90708 at something.invalid>,
Greg Ewing <see_reply_address at something.invalid> wrote:
> I've thought about this a bit more, and I think it can be done
> a lot more simply than that. All that's needed is a pointer in
> each generator-iterator that points to the subject of the
> current yield-every statement being executed, if any.
> The next() method of the generator-iterator first checks this
> pointer, and if it's not null, does a next() on it instead.
> If it's null, or calling next() on it raises StopIteration,
> carry on executing until the next yield as usual.
> This will still require going down a chain of next() methods
> when generators are nested, but the calls will all be C calls
> and should therefore be quite fast.
Somehow I find solutions that depend on the slowness of interpreted
Python to be inelegant. But I guess that's not a serious practical
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