Last active
August 13, 2018 13:26
-
-
Save ericmjl/c91fabb847697511e0394804a5cf09e1 to your computer and use it in GitHub Desktop.
Python: create directory if it doesn't exist, using pathlib!
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
from pathlib import Path | |
import os | |
# We will use the example of creating a .directory under home. | |
home = Path.home() | |
dirname = home / '.dir' | |
if not dirname.exists(): | |
os.mkdir(dirname) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment