Python tips: create path if not exist
Feb 19, 2021
Previously, I was using this way
import os
if not os.path.exists(directory):
os.makedirs(directory)
After reading this discussion, I’d like to use the following way
from pathlib import Path
Path("/my/directory").mkdir(parents=True, exist_ok=True)