utils.py 文件源码

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

项目:Insane 作者: Tsjerk 项目源码 文件源码
def which(program):
    """Determine full path of executable *program* on :envvar:`PATH`.

    (Jay at http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python)
    """

    def is_exe(fpath):
        """
        Returns True is the path points to an executable file.
        """
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, _ = os.path.split(program)
    if fpath:
        real_program = realpath(program)
        if is_exe(real_program):
            return real_program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file
    return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号