can generators be nested?

Raymond Hettinger vze4rx4y at verizon.net
Mon Sep 1 00:12:59 CEST 2003


"Michael Sparks" <zathras at thwackety.com> wrote in message
news:mailman.1062072254.6205.python-list at python.org...
> Hi,
>
>
> Unfortunately there isn't a way of doing this - the reason is that the act
> of including the yield keyword in a function/method definition turns the
> function/method definition into a generator definition.
>
> The way you're doing it now:
> >    for i in gen2(): yield i
>
> Is the only way of doing it.
>
> I asked essentially the same question almost a year ago - I was concerned
> about the fragility of nesting yields.
>
> The fact you can't do this influenced certain aspects on the design of a
> system I'm working on for work - largely to shield users of my classes
> from the problem.
>
> The original thread where I asked the question is here:
>    *
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=alqehl%249qv%241%40nntp0.reith.bbc.co.uk&rnum=9&prev=/&frame=on


If you would like to have a 'yield every', a good first step is to
file a feature request at sourceforge.

For the truly determined, writing a PEP is the surest path to
complete issue discussion followed by a BDFL pronouncement.


Raymond Hettinger






More information about the Python-list mailing list