[Python-Dev] Acquire/release functionality (Was: Extended Function syntax)

Bernhard Herzog bh@intevation.de
03 Feb 2003 15:17:03 +0100


"Moore, Paul" <Paul.Moore@atosorigin.com> writes:

> From: Bernhard Herzog [mailto:bh@intevation.de]
> > IMO if you want multiple controllers for a with statement you
> > should just nest the withs:
> >
> > with var1 = expr1:
> >     with var2 = expr2:
> >         suite
> 
> To some extent, an important point of the with expression is to
> simplify the overall control construct, and to reduce the level
> of nesting needed. Combining the variables was intended to help
> with this.

Well, you could easily define a new class that combines several control
objects into one object so that you'd get something like this:

with obj = combine(var1 = expr1, var2 = expr2):
    suite

combine.__enter__ etc. would delegate their functionality to that of the
vars. 

In the example above you'd have no way to specify the order in which the
var methods are intended to be called although the class could guarantee
that the __exit__ methods are called in the reverse order of the
__enter__ methods. However, it wouldn't be difficult to use a different
scheme to give the programmer more control over the oder.

    Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Sketch                                 http://sketch.sourceforge.net/
MapIt!                                           http://www.mapit.de/