def ensure_file_exists(filename):
 if (not os.path.exists(filename)):
  (head, tail) = os.path.split(filename)
  ensure_dir_exists(head)
  with open(filename, 'w') as f:
   pass

def ensure_file_exists ( filename ) : if ( not os . path . exists ( filename ) ) : ( head , tail ) = os . path . split ( filename ) ensure_dir_exists ( head ) with open ( filename , 'w' ) as f : pass
given a valid filename .