[Python-ideas] with *context_managers:

Giampaolo Rodolà g.rodola at gmail.com
Mon Apr 2 13:40:43 CEST 2012


Il 01 aprile 2012 22:25, Ram Rachum <ram.rachum at gmail.com> ha scritto:
> I'd like to be able to do this:
>
> with *context_managers:
>     pass # Some suite.
>
>
> This is useful when you have an unknown number of context managers that you
> want to use. I currently use `contextlib.nested`, but I'd like the *star
> syntax much better.
>
> What do you think?
>
>
> Ram.

I believe writing a specialized context manager object which is able
to hold multiple context managers altogheter is better than
introducing a new syntax for such a use case which should be pretty
rare/uncommon.
Also, it's not clear what to expect from "with *context_managers as ctx: ...".

Regards,

--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/
http://code.google.com/p/pysendfile/



More information about the Python-ideas mailing list