Skip to content

Instantly share code, notes, and snippets.

@ericmjl
Last active August 13, 2018 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericmjl/c91fabb847697511e0394804a5cf09e1 to your computer and use it in GitHub Desktop.
Save ericmjl/c91fabb847697511e0394804a5cf09e1 to your computer and use it in GitHub Desktop.
Python: create directory if it doesn't exist, using pathlib!
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