Combine two context managers into one

Viewed 5141

I use Python 2.7 and I know that I can write this:

with A() as a, B() as b:
    do_something()

I want to provide a convenience helper which does both. The usage of this helper should look like this:

with AB() as ab:
    do_something()

Now AB() should do both: Create context A() and create context B().

I have no clue how to write this convenience helper

1 Answers
Related