Emily Morehouse <[email protected]> added the comment:
This is an interesting behavior to note. I think the current behavior makes the
most sense, as it corresponds to the OS-level errors that you get from running
the same operations.
Interestingly, at least on Unix-based file systems, we get different error
messages but the same behavior when using "" vs "." as our target:
[linux]$ mkdir ""
mkdir: cannot create directory ‘’: No such file or directory
[linux]$ mkdir .
mkdir: cannot create directory ‘.’: File exists
[mac]$ mkdir ""
mkdir: .: No such file or directory
[mac]$ mkdir .
mkdir: .: File exists
Both os.mkdir and os.makedirs follow (only os.mkdir is included as the
traceback is cleaner, but they raise the same errors):
>>> os.mkdir("")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: ''
>>> os.mkdir(".")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FileExistsError: [Errno 17] File exists: '.'
Since on an OS level the only time "File exists" is returned is when using "."
and not "", os.makedirs with exists_ok=True also follows:
>>> os.makedirs("", exist_ok=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/os.py",
line 220, in makedirs
mkdir(name, mode)
FileNotFoundError: [Errno 2] No such file or directory: ''
>>> os.makedirs(".", exist_ok=True)
>>>
Basically, the FileExistsError gets silenced, but FileNotFoundError is left
alone. I can see how the differences are nuanced and not obvious though.
Unless you think there is a succinct and worthwhile way of adding this to the
documentation, I think this issue can be closed.
----------
nosy: +emilyemorehouse
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue33968>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com