[Python-ideas] with *context_managers:

Eric V. Smith eric at trueblade.com
Mon Apr 2 14:24:32 CEST 2012

On 4/2/2012 7:40 AM, Giampaolo Rodolà wrote:
> 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: ...".

See http://bugs.python.org/issue13585

More information about the Python-ideas mailing list