[issue30012] gzip.open(filename, "rt") fails on Python 2.7.11 on win32, invalid mode rtb

Martin Panter report at bugs.python.org
Fri Apr 7 19:23:14 EDT 2017


Martin Panter added the comment:

I agree this is not a bug. It is just one of the unfortunate compatibility breaks between Py 2 and 3. Mode="rt" is not one of the values that are supported according to the documentation; adding support would be a new feature.

I understand the file mode handling is stricter on Windows because the underlying OS or C library would crash.

To have code that works with Py 2 and 3, I would switch the mode depending on the version of Python:

if sys.version_info >= (3,):
    handle = gzip.open(filename, "rt")
else:
    handle = gzip.open(filename)

----------
nosy: +martin.panter
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue30012>
_______________________________________


More information about the Python-bugs-list mailing list