diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst --- a/Doc/library/contextlib.rst +++ b/Doc/library/contextlib.rst @@ -366,17 +366,17 @@ documentation: supporting a variable num cleanup operations in a single :keyword:`with` statement. The variability may come from the number of context managers needed being driven by user input (such as opening a user specified collection of files), or from some of the context managers being optional:: with ExitStack() as stack: for resource in resources: stack.enter_context(resource) - if need_special resource: + if need_special_resource: special = acquire_special_resource() stack.callback(release_special_resource, special) # Perform operations that use the acquired resources As shown, :class:`ExitStack` also makes it quite easy to use :keyword:`with` statements to manage arbitrary resources that don't natively support the context management protocol.