Make a directory safely without raising error
Use “exist_ok” parameter of makedirs method of os library to make a directory without an error.
# Imports import os # Let's define the path where we want a new directory path = "D:\\New folder\\newdir" # exist_ok = True doesn't create folder if it already exists and doesn't raise an error os.makedirs(path, exist_ok=True)
That's how we Make a directory safely without raising error
That’s all for this mini tutorial. To sum it up, we learned how to Make a directory safely without raising error.
Hope it was easy, cool and simple to follow. Now it’s on you.