Last active
September 10, 2015 09:53
-
-
Save YS-L/ee38c8b0b5f7cfe9ada6 to your computer and use it in GitHub Desktop.
Create directory if necessary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mkdir_p(directory): | |
"""Create a directory if necessary""" | |
# Thread safe | |
import os | |
try: | |
os.makedirs(directory) | |
except OSError: | |
pass | |
def mkdir_p_for(fname): | |
"""Create a directory for a file if necessary""" | |
import os | |
dirname = os.path.dirname(fname) | |
if dirname != '': | |
mkdir_p(dirname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment