From dbc0c6d23f77f0d2186df4e944d9333991770b13 Mon Sep 17 00:00:00 2001 From: Nick Coghlan <@ncoghlan> Date: Thu, 15 Dec 2011 22:30:55 +1000 Subject: [PATCH] Add link back to original tracker issue, fix typo noticed by Chris Neugebauer --- contextlib2.py | 5 +++-- docs/index.rst | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/contextlib2.py b/contextlib2.py index f99bbee..f02a381 100644 --- a/contextlib2.py +++ b/contextlib2.py @@ -141,13 +141,14 @@ class closing(object): self.thing.close() +# Inspired by discussions on http://bugs.python.org/issue13585 class ContextStack(object): - """Context for programmatic management of resource cleanup + """Context manager for programmatic management of resource cleanup For example: with ContextStack() as stack: - files = [stack.enter_context(fname) for fname in filenames] + files = [stack.enter_context(open(fname)) for fname in filenames] # All opened files will automatically be closed at the end of # the with statement, even if attempts to open files later # in the list throw an exception diff --git a/docs/index.rst b/docs/index.rst index 93192aa..e4be3a3 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -199,7 +199,7 @@ API Reference statement as follows:: with ContextStack() as stack: - files = [stack.enter_context(fname) for fname in filenames] + files = [stack.enter_context(open(fname)) for fname in filenames] # All opened files will automatically be closed at the end of # the with statement, even if attempts to open files later # in the list throw an exception