What is the best way to check if the directory a file is going to be written to exists, and if not, how to create the directory using Python?
Does a flag exists as "open", that makes this happen automatically?
What is the best way to check if the directory a file is going to be written to exists, and if not, how to create the directory using Python?
Does a flag exists as "open", that makes this happen automatically?
Use makedirs
from os
module:
os.makedirs(DIRECTORY, exist_ok=True)
This will create a directory if it doesn't exist.