New submission from Fabian: I had a weird bug recently where someone tried to use the with-statement on a BZ2File. According to the documentation it was added in 2.7 and looking at https://hg.python.org/cpython/rev/5d5d9074f4ca it looks like it was added together with the support in gzip.
But after I've installed 2.7.0 I could use the with-statement on gzip but not in BZ2File: Python 2.7 (r27:82500, Jun 7 2015, 19:01:29) [GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux3 Type "help", "copyright", "credits" or "license" for more information. >>> import bz2 >>> with bz2.BZ2File('tests/data/xml/article-pyrus.xml.bz2') as f: ... c = f.read() ... Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: __exit__ So I've installed 2.7.1 and sure enough it works there: Python 2.7.1 (r271:86832, Jun 7 2015, 19:21:02) [GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux3 Type "help", "copyright", "credits" or "license" for more information. >>> import bz2 >>> with bz2.BZ2File('tests/data/xml/article-pyrus.xml.bz2') as f: ... c = f.read() ... >>> I guess the documentation needs be updated that since Python 2.7.1 BZ2File supports the with-statement. See also: https://phabricator.wikimedia.org/T101649 ---------- assignee: docs@python components: Documentation messages: 244962 nosy: docs@python, xZise priority: normal severity: normal status: open title: Python 2.7.0's BZ2File does not support with-statements versions: Python 2.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue24404> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com