question about generators

Neil Schemenauer nas at
Fri Aug 16 19:00:45 CEST 2002

Tim Peters wrote:
> I thought of it as pure syntactic sugar,
>     yield every expr
> same-as
>     for _tempname in expr:
>         yield _tempname


> > Also, does it allow the generator-iterator to be passed?
> Couldn't parse that one.

I meant that would it work if you called a function that returned a
generator-iterator (as opposed to calling a generator-function).

> Since grange_wrapper() above doesn't accept an argument, it's unclear
> whether you're asking about exception behavior here.

I should be more careful when I type examples.  grange_wrapper was
supposed to take an argument just like grange().  Forget the examples.
Your proposed 'yield every' would accept any object that supported the
iterator protocol.  In that case, David Eppstein's idea of optimizing
away the extra 'for' loop would be difficult.

It's not a big problem, IMO.  I'd much rather have the extra
flexibility.  The loop would be efficient since it could be implemented
as a C function (like map()) instead of having to go through the VM.
Have you pitched 'yield every' to Guido yet?  Is it worth trying to come
up with a patch?


More information about the Python-list mailing list