What is the most elegant way to check if the directory a file is going to be written to exists, and if not, create the directory using Python? Here is what I tried:
Try the os.path.exists function
if not os.path.exists(dir): os.mkdir(dir)