Zum Hauptinhalt springen
🔒 Vorschaumodus. Die ersten fünfzehn Foundations-Lektionen sind kostenlos; diese hier ist Pro. Starte einen 7-Tage-Trial, um den Editor, AI-Hinweise und den Rest des Lehrplans freizuschalten. Karte erforderlich, jederzeit im Dashboard kündbar.7-Tage-Trial starten →
← KurseSenior Deep-DivesModule 1 · Concurrency internals · RecapExitStack für dynamisches Kontextmanagementpredict23 / 161
+100 XP
Aufgabe🌐 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.
Sage die Ausgabe vorher

Lies den Code sorgfältig

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")

Was wird das Programm ausgeben? Schreib hier: