[Python-ideas] With clauses for generator expressions

Serhiy Storchaka storchaka at gmail.com
Thu Nov 15 13:16:42 CET 2012

On 15.11.12 13:11, Andrew Barnert wrote:
> Which means the only question is, which one looks more readable:
> 1. (foo(line) for line in baz(f) if 'bar' in line with open('foo') as f)
> 2. (foo(line) for line in baz(f) with open('foo') as f if 'bar' in line)
> 3. (foo(line) with open('foo') as f for line in baz(f) if 'bar' in line)

What about such generator?

def gen():
     with a() as f:
         for x in f:
             if p(x):
                 with b(x) as g:
                     for y in g:
                         if q(y):
                             yield y

More information about the Python-ideas mailing list