[Python-ideas] Nested with statements

Carl Johnson cmjohnson.mailinglist at gmail.com
Wed Apr 29 06:25:44 CEST 2009

Mathias Panzenböck wrote:
> Pascal Chambon wrote:
>> Then just call* delayedNested(partial(A,...arguments...), partial(B,
>> ...arguments...))*/ /to have what you want.
> It would be much shorter and more readable to manually nest the with
> statements.

You could improve the look a little by changing the input excepted. Say:

with delaynested( [A, B], [(A_arg1, A_arg2), B_args]):

A realistic example:

with delaynested([getlock, open], [None, ("file.txt",)]): #Notice that
the comma is important!

Is that so bad? I think it looks OK.

That said, it would be nice if there were a better way to do partial
functions than either lambda or functools.partial.

-- Carl

More information about the Python-ideas mailing list