Skip to main content


With more than one item, the context managers are processed as if multiple with statements were nested:
with A() as a, B() as b:
    SUITE

is semantically equivalent to:

with A() as a:
    with B() as b:
        SUITE

You can also write multi-item context managers in multiple lines if the items are surrounded by parentheses. For example:

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

:O #Python

Tech Cyborg reshared this.

in reply to Neil E. Hodges

Non-GC languages with destructors: "Look what they need to mimic a fraction of our power!"