Message244962
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 |
|
Date |
User |
Action |
Args |
2015-06-07 17:45:25 | xZise | set | recipients:
+ xZise, docs@python |
2015-06-07 17:45:24 | xZise | set | messageid: <1433699124.98.0.649145124993.issue24404@psf.upfronthosting.co.za> |
2015-06-07 17:45:24 | xZise | link | issue24404 messages |
2015-06-07 17:45:24 | xZise | create | |
|