syswraps.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:ribolands 作者: bad-ants-fleet 项目源码 文件源码
def which(program):
  """ Emulates the unix ``which`` command. Snatched from:
    `http://stackoverflow.com/questions/377017/
      test-if-executable-exists-in-python`

    :param program: executable
    :type program: string

    :returns: path-to-executable or None
  """
  def is_exe(fpath):
    return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

  fpath, fname = os.path.split(program)
  if fpath:
    if is_exe(program):
      return program
  else:
    for path in os.environ["PATH"].split(os.pathsep):
      path = path.strip('"')
      exe_file = os.path.join(path, program)
      if is_exe(exe_file):
        return exe_file

  return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号