From ce77ee9183fd6b6096e3bedb48a06a459deeec92 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Fri, 13 Mar 2015 02:29:54 +0200 Subject: [PATCH] Issue #22154: Add an example to show context management protocol support of ZipFile.open(). Patch by Mike Short. --- Doc/library/zipfile.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Doc/library/zipfile.rst b/Doc/library/zipfile.rst index 1d23a7c4d2e..b416bf7e184 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: