Naar hoofdinhoud
πŸ”’ Voorbeeldmodus. De eerste vijftien Foundations-lessen zijn gratis; deze is Pro. Start een 7-daagse trial om de editor, AI-hints en de rest van het curriculum te ontgrendelen. Kaart vereist, op elk moment opzegbaar in Dashboard.Start 7-daagse trial β†’
⚑
← Cursussenβ€ΊSenior Deep-DivesModule 1 Β· Concurrency internals Β· Recapβ€ΊExitStack voor dynamisch contextbeheerpredict23 / 161
+100 XP
Opdracht🌐 shown in EN
πŸ“ **Question:** Predict the exact output. \`res(name)\` is a tiny context manager that prints \`open:\` / \`close:\`. Three resources enter an \`ExitStack\` in order A β†’ B β†’ C. When the \`with\` exits, what order do they close in? πŸ“‹ Pick the right answer. πŸ’‘ **Hint:** Re-read the theory above if unsure.
Voorspel uitvoer

Lees de code zorgvuldig

from contextlib import ExitStack, contextmanager


@contextmanager
def res(name):
    print(f"open:{name}")
    try:
        yield name
    finally:
        print(f"close:{name}")


with ExitStack() as stack:
    a = stack.enter_context(res("A"))
    b = stack.enter_context(res("B"))
    c = stack.enter_context(res("C"))
    print(f"use:{a}{b}{c}")

print("done")

Wat zal het programma uitprinten? Schrijf hier: