This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: fileinput.input(path, inplace=True) crashes for valid filename with 252-255 characters
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jamil.raichouni
Priority: normal Keywords:

Created on 2021-12-02 15:46 by jamil.raichouni, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
long_filename_passed_to_fileinput.ipynb jamil.raichouni, 2021-12-02 15:46 Example Jupyter notebook showcasing that fileinput cannot handle a valid file
Messages (1)
msg407534 - (view) Author: Jamil Raichouni (jamil.raichouni) * Date: 2021-12-02 15:46
import fileinput
from pathlib import Path
path = Path(252 * "x")
path.write_text("")
for line in fileinput.input(path, inplace=True):
    pass

raises an

OSError: [Errno 63] File name too long

for perfectly valid (yes, quite long) file names.

Reason:

Internally the fileinput library creates a backup file when we pass 'inplace=True' to fileinput.input() and that backup file gets a file name that is longer than the name for the file of interest.

Enhancement idea:

Work with a backup file name that is sth like GUID.bak or remove some chars from the original file name.

Hint:

vim /path/to/my/file creates a .swp file and can handle very long file names with 252-255 chars.
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90123
2021-12-02 15:46:58jamil.raichounicreate