def find_file_in_dirs(path, dirs):
 if os.path.isabs(path):
  return path
 for d in dirs:
  if (d == '.'):
   f = path
  else:
   d = os.path.expanduser(d)
   f = os.path.join(d, path)
  if os.path.exists(f):
   return f
 return path

def find_file_in_dirs ( path , dirs ) : if os . path . isabs ( path ) : return path for d in dirs : if ( d == '.' ) : f = path else : d = os . path . expanduser ( d ) f = os . path . join ( d , path ) if os . path . exists ( f ) : return f return path
search for path in the list of directories dirs .