def which(program):
def is_exe(fpath):<EOL><INDENT>"""<STR_LIT>"""<EOL>return os.path.isfile(fpath) and os.access(fpath, os.X_OK)<EOL><DEDENT>fpath, _ = os.path.split(program)<EOL>if fpath:<EOL><INDENT>real_program = realpath(program)<EOL>if is_exe(real_program):<EOL><INDENT>return real_program<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for path in os.environ["<STR_LIT>"].split(os.pathsep):<EOL><INDENT>exe_file = os.path.join(path, program)<EOL>if is_exe(exe_file):<EOL><INDENT>return exe_file<EOL><DEDENT><DEDENT><DEDENT>return None<EOL>
Determine full path of executable *program* on :envvar:`PATH`.

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