On Tue, Aug 2, 2011 at 6:11 PM, Mark McDuff <mmcduff@gmail.com> wrote:
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
The parts of the for statement have no connection at all to the parts of the with statement. They're just stuck together which doesn't make much sense to me.
When I read the subject of the original mail I immediately thought of this case:
with open(foo) as _:
for line in _:
# stuff
which would at least make some sense if we could splice these together as
with line in open(foo):
#stuff
But no matter how common this might be, I have to agree with:
On Tue, Aug 2, 2011 at 9:32 PM, Chris Rebert <pyideas@rebertia.com> wrote:
... Down this path lies Perl ...
For every combination like this, there's another one just past it on the road to Perl.