[New-bugs-announce] [issue24404] Python 2.7.0's BZ2File does not support with-statements

Fabian report at bugs.python.org
Sun Jun 7 19:45:24 CEST 2015


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 at python
components: Documentation
messages: 244962
nosy: docs at 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 <report at bugs.python.org>
<http://bugs.python.org/issue24404>
_______________________________________


More information about the New-bugs-announce mailing list