code: def ensure_dir(path):
      
      if not os.path.exists(path):
          # path does not exist, create the directory
          os.mkdir(path)
      else:
          # The path exists, check that it is not a file
          if os.path.isfile(path):
              raise Exception("Path %s already exists, and it is a file, not a directory" % path)
docs: :param path: path to directory to be created
  
      Create a directory if it does not already exist.