[Python-ideas] With clauses for generator expressions

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Nov 15 22:17:58 CET 2012

Andrew Barnert wrote:
> 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)

Order 3 is the most consistent with existing features. The
only out-of-order thing about comprehensions currently is that
the result expression comes first instead of last. Everything
else is in the same order as the statement expansion.


More information about the Python-ideas mailing list