[Python-checkins] cpython (merge 3.4 -> default): Issue #22154: Add an example to show context management protocol support of
berker.peksag
python-checkins at python.org
Fri Mar 13 01:29:12 CET 2015
https://hg.python.org/cpython/rev/390a2f4dfd4a
changeset: 94966:390a2f4dfd4a
parent: 94964:9332a545ad85
parent: 94965:b6fdf8c7a74d
user: Berker Peksag <berker.peksag at gmail.com>
date: Fri Mar 13 02:30:17 2015 +0200
summary:
Issue #22154: Add an example to show context management protocol support of ZipFile.open().
Patch by Mike Short.
files:
Doc/library/zipfile.rst | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst
--- a/Doc/library/zipfile.rst
+++ b/Doc/library/zipfile.rst
@@ -210,6 +210,13 @@
password used for encrypted files. Calling :meth:`.open` on a closed
ZipFile will raise a :exc:`RuntimeError`.
+ :func:`~ZipFile.open` is also a context manager and therefore supports the
+ :keyword:`with` statement::
+
+ with ZipFile('spam.zip') as myzip:
+ with myzip.open('eggs.txt') as myfile:
+ print(myfile.read())
+
.. note::
The file-like object is read-only and provides the following methods:
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list