diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2009-12-30 06:14:51 +0000 |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2009-12-30 06:14:51 +0000 |
commit | 569e61f35196cb765eb9940f75b27bb765e73073 (patch) | |
tree | 3bf8941cf86c15a9a6f9c4afbeb68211436e826b /Lib/zipfile.py | |
parent | eb74da8e67bed4beef1bfc97384b3aa6e0f9836b (diff) | |
download | cpython-git-569e61f35196cb765eb9940f75b27bb765e73073.tar.gz |
#5511: Added the ability to use ZipFile as a context manager. Patch by Brian Curtin.
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r-- | Lib/zipfile.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py index 2aa4bffc42..89b4166f38 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -721,6 +721,12 @@ class ZipFile: self.fp = None raise RuntimeError, 'Mode must be "r", "w" or "a"' + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + self.close() + def _GetContents(self): """Read the directory, making sure we close the file if the format is bad.""" |