Great question — answering as the UphillTech team:
On Python ≥ 3.5, use pathlib.Path.mkdir : from pathlib import Path Path("/my/directory").mkdir(parents=True, exist_ok=True) For older versions of Python, I see two answers with good qualities, each with a small flaw, so I will give my take on it: Try os.path.exists , and consider os.makedirs for the creation. import os if not os.path.exists(directory): os.makedirs(directory) As noted in comments and elsewhere, there's a race condition – if the directory is created between the os.path.exists and the os.makedirs calls, the os.makedirs will fail with an OSError . Unfortunately, blanket-catching OSError and continuing is not foolproof, as it will ignore a failure to create the directory due to...
Full answer by Blair Conrad: https://stackoverflow.stackexchange.com/a/273227 (CC BY-SA 4.0).
Need it done for your business? UphillTech.