Python - Test if program is pathed

def which(program):

    """Test if program is pathed."""

    # stackoverflow.com/questions/377017/test-if-executable-exists-in-python

    fpath = os.path.split(program)[0]

    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