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 Hong Xu
Recipients Hong Xu, paul.moore, steve.dower, tim.golden, zach.ware
Date 2021-01-09.08:15:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1610180126.52.0.315552258683.issue42872@roundup.psfhosted.org>
In-reply-to
Content
Consider the following code:

-------------------------

import pathlib

def main():
    pathlib.Path('tmp').touch()
    pathlib.Path('tmp/tmp_sub').mkdir(parents=True)

main()

------------------------

Run the code above in an empty directory.

On Linux, it throws a `NotADirectory` exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "main.py", line 5, in main
    pathlib.Path('tmp/tmp_sub').mkdir(parents=True)
  File "/usr/lib/python3.8/pathlib.py", line 1287, in mkdir
    self._accessor.mkdir(self, mode)
NotADirectoryError: [Errno 20] Not a directory: 'tmp/tmp_sub'

-----------------------------

On Windows, it throws a FileExistsError exception:

Traceback (most recent call last):
  File "C:\Users\hong\anaconda3\lib\pathlib.py", line 1284, in mkdir
    self._accessor.mkdir(self, mode)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'tmp\\tmp_sub'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 7, in <module>
    main()
  File "main.py", line 5, in main
    pathlib.Path('tmp/tmp_sub').mkdir(parents=True)
  File "C:\Users\hong\anaconda3\lib\pathlib.py", line 1288, in mkdir
    self.parent.mkdir(parents=True, exist_ok=True)
  File "C:\Users\hong\anaconda3\lib\pathlib.py", line 1284, in mkdir
    self._accessor.mkdir(self, mode)
FileExistsError: [WinError 183] Cannot create a file when that file already exists: 'tmp
History
Date User Action Args
2021-01-09 08:15:26Hong Xusetrecipients: + Hong Xu, paul.moore, tim.golden, zach.ware, steve.dower
2021-01-09 08:15:26Hong Xusetmessageid: <1610180126.52.0.315552258683.issue42872@roundup.psfhosted.org>
2021-01-09 08:15:26Hong Xulinkissue42872 messages
2021-01-09 08:15:25Hong Xucreate