[Python-ideas] With clauses for generator expressions

Serhiy Storchaka storchaka at gmail.com
Thu Nov 15 15:37:59 CET 2012


On 15.11.12 16:25, Andrew Barnert wrote:
> Mechanically transforming that is easy. You just insert each with along with its
> corresponding for and if. There are no ambiguities for any of the three
> potential rules:
>
> 1. (y for x in f if p(x) with a() as f for y in g if q(y) with b(x) as g)
> 2. (y for x in f with a() as f if p(x) for y in g with b(x) as g if q(y))
> 3. (y with a() as f for x in f if p(x) with b(x) as g for y in g if q(y))

And what about this (only one for/if for simplicity)?

     with a() as f:
         for x in f:
             with b() as g:
                 if p(x):
                     with c() as h:
                         yield x





More information about the Python-ideas mailing list