[Python-checkins] cpython (3.4): Issue #22154: Add an example to show context management protocol support of
berker.peksag
python-checkins at python.org
Fri Mar 13 01:29:11 CET 2015
https://hg.python.org/cpython/rev/b6fdf8c7a74d
changeset: 94965:b6fdf8c7a74d
branch: 3.4
parent: 94963:7522bb14e36a
user: Berker Peksag <berker.peksag at gmail.com>
date: Fri Mar 13 02:29:54 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