diff options
author | Berker Peksag <berker.peksag@gmail.com> | 2015-03-13 00:30:17 (GMT) |
---|---|---|
committer | Berker Peksag <berker.peksag@gmail.com> | 2015-03-13 00:30:17 (GMT) |
commit | 406221ccd9048f48ba259cd545d69c3f7db08784 (patch) | |
tree | b5849cc2cf32283569dad9a8a07508cf7457c97d /Doc/library/zipfile.rst | |
parent | c2ccce791ccbe35bee0edea2dedabb0fc7ea5906 (diff) | |
parent | ce77ee9183fd6b6096e3bedb48a06a459deeec92 (diff) | |
download | cpython-406221ccd9048f48ba259cd545d69c3f7db08784.zip cpython-406221ccd9048f48ba259cd545d69c3f7db08784.tar.gz cpython-406221ccd9048f48ba259cd545d69c3f7db08784.tar.bz2 |
Issue #22154: Add an example to show context management protocol support of ZipFile.open().
Patch by Mike Short.
Diffstat (limited to 'Doc/library/zipfile.rst')
-rw-r--r-- | Doc/library/zipfile.rst | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst index 465d786..faef6af 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: |