# 04 · exit-stack **演示**:`ExitStack.enter_context` 按进入顺序登记、按**逆序**释放,与嵌套 `with` 一致。 **运行**: ```sh uv run python examples/09-exceptions-context-managers/04-exit-stack/exit_stack.py ``` **预期输出**(3.12.9): ```text nested: ['open:a', 'open:b', 'body', 'close:b', 'close:a'] stacked: ['open:a', 'open:b', 'body', 'close:b', 'close:a'] ``` **依赖**:仅标准库。 **注意**:动态数量资源、需要条件进入时用 `ExitStack`;固定数量优先嵌套 `with`。