summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2015-03-13 00:29:54 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2015-03-13 00:29:54 (GMT)
commitce77ee9183fd6b6096e3bedb48a06a459deeec92 (patch)
tree782fbf2a1082f4f8d3d46f11ad1c9016ecaa3095 /Doc
parenta60c2fe4807e89a5844979fe46b3ea39572fc3be (diff)
downloadcpython-ce77ee9183fd6b6096e3bedb48a06a459deeec92.zip
cpython-ce77ee9183fd6b6096e3bedb48a06a459deeec92.tar.gz
cpython-ce77ee9183fd6b6096e3bedb48a06a459deeec92.tar.bz2
Issue #22154: Add an example to show context management protocol support of ZipFile.open().
Patch by Mike Short.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/zipfile.rst7
1 files changed, 7 insertions, 0 deletions
diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst
index 1d23a7c..b416bf7 100644
--- a/Doc/library/zipfile.rst
+++ b/Doc/library/zipfile.rst
@@ -210,6 +210,13 @@ ZipFile Objects
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: