[issue36865] FileInput does not allow 'rt' mode, but all its existing delegates do

Berker Peksag report at bugs.python.org
Sun May 12 07:40:00 EDT 2019


Berker Peksag <berker.peksag at gmail.com> added the comment:

Thank you for the report and the PR!

I think accepting 'rt' mode is a good idea. However, it's a new feature and it can only go into 3.8.

It seems to me that the root cause of the issue is that the fileinput module wasn't properly converted to support Python 3. Perhaps we could change 'r' to 'rt' in FileInput.__init__() or hook_compressed() to make it work properly, so the example in issue 5758 would work as expected without changing any user code:

# test.py

import fileinput

for line in fileinput.FileInput(openhook=fileinput.hook_compressed):
    print(line.rstrip())


$ ./python.exe test.py mike.txt mike.txt.gz
Hello from Mike.
This is the second line.
Why did the robot cross the road?
Hello from Mike.
This is the second line.
Why did the robot cross the road?

----------
nosy: +serhiy.storchaka

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


More information about the Python-bugs-list mailing list