summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2013-05-10 15:35:38 (GMT)
committerBarry Warsaw <barry@python.org>2013-05-10 15:35:38 (GMT)
commitd8f870d0faad949fa6ad073d35bc45ebf7074452 (patch)
tree42ba3e97d8aa1c2685996ca32e7eaeeeaeac4025 /Doc/library
parent173d4109b59f64eeb29601efb08497008d42dd2b (diff)
downloadcpython-d8f870d0faad949fa6ad073d35bc45ebf7074452.zip
cpython-d8f870d0faad949fa6ad073d35bc45ebf7074452.tar.gz
cpython-d8f870d0faad949fa6ad073d35bc45ebf7074452.tar.bz2
I was confused before. It's correct to not call .close() inside the with
statement, but add a comment that clarifies the purpose of the code.
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/contextlib.rst5
1 files changed, 3 insertions, 2 deletions
diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst
index fee5067..fba48f4 100644
--- a/Doc/library/contextlib.rst
+++ b/Doc/library/contextlib.rst
@@ -259,11 +259,12 @@ Functions and classes provided:
with ExitStack() as stack:
files = [stack.enter_context(open(fname)) for fname in filenames]
- close_files = stack.pop_all().close()
+ # Hold onto the close method, but don't call it yet.
+ close_files = stack.pop_all().close
# If opening any file fails, all previously opened files will be
# closed automatically. If all files are opened successfully,
# they will remain open even after the with statement ends.
- # close_files() can then be invoked explicitly to close them all
+ # close_files() can then be invoked explicitly to close them all.
.. method:: close()