code: def ensure_dir_exists(f, fullpath=False):
      
      if fullpath is False:
          # Get parent directory
          d = os.path.dirname(f)
      else:
          # Create the full path
          d = f
      if not os.path.exists(d):
          os.makedirs(d)
docs: Ensure the existence of the (parent) directory of f