def find_python_in_context(context):
    """Find Python executable within the given context.

    Args:
        context (ResolvedContext): Resolved context with Python and pip.
        name (str): Name of the package for Python instead of "python".
        default (str): Force a particular fallback path for Python executable.

    Returns:
        str or None: Path to Python executable, if any.
    """

    # Create a copy of the context with systems paths removed, so we don't
    # accidentally find a system python install.
    #
    context = context.copy()
    context.append_sys_path = False  # GitHub nerdvegas/rez/issue/826

    python_package = context.get_resolved_package("python")
    assert python_package

    # look for (eg) python3.7, then python3, then python
    name_template = "python{}"
    for trimmed_version in map(python_package.version.trim, [2, 1, 0]):
        exe_name = name_template.format(trimmed_version)
        py_exe_path = context.which(exe_name)
        if py_exe_path:
            return py_exe_path

    return None