[Python-ideas] combine for/with statement

Mark McDuff mmcduff at gmail.com
Wed Aug 3 03:11:28 CEST 2011

I find that I am often writing code in the following pattern:

foo = MyContextManager(*args)
for bar in my_iter:
   with foo:
       # do stuff

I think it would be much cleaner to be able to write:

for bar in my_iter with MyContextManager(*args):
   # do stuff


More information about the Python-ideas mailing list