mirror of
https://github.com/AdaCore/cpython.git
synced 2026-02-12 12:57:15 -08:00
Issue #22154: Add an example to show context management protocol support of ZipFile.open().
Patch by Mike Short.
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user