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.

Author danny87105
Recipients danny87105
Date 2020-09-07.15:36:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1599492997.14.0.974001441191.issue41737@roundup.psfhosted.org>
In-reply-to
Content
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?
History
Date User Action Args
2020-09-07 15:36:37danny87105setrecipients: + danny87105
2020-09-07 15:36:37danny87105setmessageid: <1599492997.14.0.974001441191.issue41737@roundup.psfhosted.org>
2020-09-07 15:36:37danny87105linkissue41737 messages
2020-09-07 15:36:37danny87105create