[issue13989] gzip always returns byte strings, no text mode
Nadeem Vawda
report at bugs.python.org
Sat Feb 11 14:55:56 CET 2012
Nadeem Vawda <nadeem.vawda at gmail.com> added the comment:
The problem here is that gzip.GzipFile does not support text mode, only
binary mode. Unfortunately, its __init__ method doesn't handle unexpected
mode strings sensibly, so you get a confusing error message.
If you need to open a compressed file in text mode in Python 3.2, use
io.TextIOWrapper:
with io.TextIOWrapper(gzip.open("ex1.sam.gz", "r")) as f:
line = f.readline()
In 3.3, it would be nice for gzip.open to do this transparently when mode
is "rt"/"wt"/"at". However, binary mode will still need to be the default
(for modes "r", "w" and "a"), to ensure backward compatibility.
In the meanwhile, I'll add a note to the documentation about this
limitation, and fix GzipFile.__init__ to produce a more sensible error
message.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13989>
_______________________________________
More information about the Python-bugs-list
mailing list