1import os
2if not os.path.exists('my_folder'):
3 os.makedirs('my_folder')
1from pathlib import Path
2Path("/my/directory").mkdir(parents=True, exist_ok=True) #python 3.5 above
1try:
2 os.makedirs("path/to/directory")
3except FileExistsError:
4 # directory already exists
5 pass
6