[issue5758] fileinput.hook_compressed returning bytes from gz file

Inada Naoki report at bugs.python.org
Tue May 25 00:04:56 EDT 2021


Inada Naoki <songofacandy at gmail.com> added the comment:

> I'm struggling with how to adapt the code to provide a uniform interface on Python 3.6+.

It's easy. Just passing `mode="rb"`.

```
FileInput(filelist, mode="rb", openhook=fileinput.hook_compressed)
```

This is better than `backports.hook_compressed`, because it returns bytes always regardless file is compressed or uncompressed.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue5758>
_______________________________________


More information about the Python-bugs-list mailing list