Debian Codegraph @

docs/dev/logs/2012-05-24.makedirs.py-python3.1

raw
1 # From curl http://armstrong.cc/~steven/tmp/makedirs.py:
2
3 #!/usr/bin/env python2
4
5 import os
6
7 def makedirs(path, mode=0o777, exist_ok=False):
8 try:
9 os.makedirs(path, mode=mode, exist_ok=exist_ok)
10 except TypeError:
11 try:
12 os.makedirs(path, mode=mode)
13 except OSError as e:
14 if exist_ok and e.errno == 17: # File exists
15 pass
16 else:
17 raise
18
19
20 makedirs('/tmp/python/makedirs')
21
22 try:
23 makedirs('/tmp/python/makedirs')
24 except OSError as e:
25 print(e)
26
27 makedirs('/tmp/python/makedirs', exist_ok=True)