New submission from Danny Lin <danny0...@gmail.com>:
On Linux (tested on Ubuntu 16.04), if "/path/to/file" is an existing file, the code: open('/path/to/file/somename.txt') raises NotADirectoryError: [Errno 20] Not a directory: '/path/to/file/somename.txt' On Windows, similar code: open(r'C:\path\to\file\somename.txt') raises FileNotFoundError: [Errno 2] No such file or directory: 'C:\\path\\chrome\\to\\file\\somename.txt' I think the behavior on Linux is not correct. The user probably cares about the existence of the file to be opened, rather than whether its ancestor directories are valid. OTOH, if NotADirectoryError should be raised, it should mention '/path/to/file' rather then '/path/to/file/somename.txt'. But what if '/path/to' or '/path' is actually a file? Should it be '/path/to' or '/path' instead for the same reason? ---------- messages: 376505 nosy: danny87105 priority: normal severity: normal status: open title: Improper NotADirectoryError when opening a file under a fake directory type: behavior versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41737> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com