Message384715
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 |
|
Date |
User |
Action |
Args |
2021-01-09 08:15:26 | Hong Xu | set | recipients:
+ Hong Xu, paul.moore, tim.golden, zach.ware, steve.dower |
2021-01-09 08:15:26 | Hong Xu | set | messageid: <1610180126.52.0.315552258683.issue42872@roundup.psfhosted.org> |
2021-01-09 08:15:26 | Hong Xu | link | issue42872 messages |
2021-01-09 08:15:25 | Hong Xu | create | |
|