[Python-Dev] PEP 343 - Abstract Block Redux

Guido van Rossum gvanrossum at gmail.com
Tue May 17 01:52:49 CEST 2005


[Ron Adam]
> So I was wondering if something like the following is feasible?
> 
[...]
> 
> with opening(file1,m),opening(file2,m),opening(file3,m) as f1,f2,f3:
>      # do stuff with files
> 
> The 'with' (or whatever) statement would need a little more under the
> hood, but it might simplify handling multiple resources.
> 
> This also reduces nesting in cases such as locking and opening. Both
> must succeed before the block executes. And if something goes wrong, the
> "with" statement knows and can handle each resource.  The point is, each
> resource needs to be a whole unit, opening multiple files in one
> resource handler is probably not a good idea anyway.

I'm -0 on this, if only because it complicates things a fair bit for a
very minor improvement in functionality. There are also some
semantic/syntactic questions: should this work only if there are
explicit commas in the with-statement (so the compiler can generate
code equivalent to nested with-statements) or should it allow a single
expression to return a tuple of resource managers dynamically (so the
run-time must check fora tuple each time)?

It's always something we can add in the future, since it's guaranteed
that this syntax (or a tuple value) is invalid in the curernt
proposal. So I'd rather punt on this.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list