This code raised exception when I tried to create a sub dir ./test/123
under ./test/
. And after examine the permission, I found that dir ./test
created by this code has d-w----r--
, which is strange...If I mkdir in the terminal, that dir will have drwxr-xr-x
permission.
from pathlib import Path
if __name__ == '__main__':
p1 = Path('./test')
p1.mkdir(644, parents=True, exist_ok=True)
p2 = Path('./test/123')
p2.mkdir(644, parents=True, exist_ok=True)
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py", line 1267, in mkdir
if not exist_ok or not self.is_dir():
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py", line 1358, in is_dir
return S_ISDIR(self.stat().st_mode)
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/pathlib.py", line 1168, in stat
return self._accessor.stat(self)
PermissionError: [Errno 13] Permission denied: 'test/123'