Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Exception using fileinput.hook_compressed in binary mode #101961

Closed
Assignees
corona100x1306e6d
Labels
stdlibStandard Library Python modules in the Lib/ directorytopic-IOtype-bugAn unexpected behavior, bug, or error
@gmacon

Description

@gmacon

Bug report

When using thefileinput.hook_compressed hook in binary mode in the case that the file isnot compressed, an exception is raised instead of processing the file like normal.

# fileinput_cat.pyimportfileinputimportsyswithfileinput.input(mode='rb',openhook=fileinput.hook_compressed)asf:forlineinf:sys.stdout.buffer.write(line)
$python3.10 fileinput_cat.py fileinput_cat.pyTraceback (most recent call last):  File "fileinput_bug.py", line 5, in <module>    for line in f:  File ".../lib/python3.10/fileinput.py", line 256, in __next__    line = self._readline()  File ".../lib/python3.10/fileinput.py", line 385, in _readline    self._file = self._openhook(self._filename, self._mode)  File ".../lib/python3.10/fileinput.py", line 432, in hook_compressed    return open(filename, mode, encoding=encoding, errors=errors)ValueError: binary mode doesn't take an encoding argument

Your environment

I tried this on Python 3.10.9 (installed from nixpkgs) on Intel macOS 11.7.3. It was working on Python 3.9.16.

Linked PRs

Metadata

Metadata

Labels

stdlibStandard Library Python modules in the Lib/ directorytopic-IOtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp