Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
23
Task/Make-directory-path/Python/make-directory-path-1.py
Normal file
23
Task/Make-directory-path/Python/make-directory-path-1.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
from errno import EEXIST
|
||||
from os import mkdir, curdir
|
||||
from os.path import split, exists
|
||||
|
||||
def mkdirp(path, mode=0777):
|
||||
head, tail = split(path)
|
||||
if not tail:
|
||||
head, tail = split(head)
|
||||
if head and tail and not exists(head):
|
||||
try:
|
||||
mkdirp(head, mode)
|
||||
except OSError as e:
|
||||
# be happy if someone already created the path
|
||||
if e.errno != EEXIST:
|
||||
raise
|
||||
if tail == curdir: # xxx/newdir/. exists if xxx/newdir exists
|
||||
return
|
||||
try:
|
||||
mkdir(path, mode)
|
||||
except OSError as e:
|
||||
# be happy if someone already created the path
|
||||
if e.errno != EEXIST:
|
||||
raise
|
||||
7
Task/Make-directory-path/Python/make-directory-path-2.py
Normal file
7
Task/Make-directory-path/Python/make-directory-path-2.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def mkdirp(path):
|
||||
try:
|
||||
os.makedirs(path)
|
||||
except OSError as exc: # Python >2.5
|
||||
if exc.errno == errno.EEXIST and os.path.isdir(path):
|
||||
pass
|
||||
else: raise
|
||||
2
Task/Make-directory-path/Python/make-directory-path-3.py
Normal file
2
Task/Make-directory-path/Python/make-directory-path-3.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
def mkdirp(path):
|
||||
os.makedirs(path, exist_ok=True)
|
||||
Loading…
Add table
Add a link
Reference in a new issue