-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GzipFile and BZ2File should support context manager protocol #48110
Comments
When you've become used to writing with open("xzy", "w") as f: it's strange when it doesn't work for gzip.open or bz2.BZ2File. |
Here is a patch for the trunk. I'm waiting for the opinion other |
Here's the StringIO discussion: bpo-1286 |
Thanks. The outcome of the StringIO discussion isn't clearly negative, |
I love "with ... as f:" and I want it for gzip/bz2 files! Comment about the patch: (1) the IOError message is different for the two modules: Specify the object name in both messages or remove it from both (2) For bz2module, Why don't you call BZ2File_close() directly instead |
I've reused the same error message as used in other parts of each
Because someone may subclass BZ2File and override the close() method. I |
Committed in trunk and py3k. Thanks! |
Documentation needs to be updated to state that these are now context managers. This is important since they aren't in python-2.x. I'm not sure whether this should be added to the "new in python" blurbs. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: