mirror of
https://github.com/python/cpython.git
synced 2025-08-19 08:11:46 +00:00
Issue #22154: Add an example to show context management protocol support of ZipFile.open().
Patch by Mike Short.
This commit is contained in:
parent
a60c2fe480
commit
ce77ee9183
1 changed files with 7 additions and 0 deletions
|
@ -210,6 +210,13 @@ ZipFile Objects
|
||||||
password used for encrypted files. Calling :meth:`.open` on a closed
|
password used for encrypted files. Calling :meth:`.open` on a closed
|
||||||
ZipFile will raise a :exc:`RuntimeError`.
|
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::
|
.. note::
|
||||||
|
|
||||||
The file-like object is read-only and provides the following methods:
|
The file-like object is read-only and provides the following methods:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue