def get_parent_var ( name , global_ok = False , default = None , skip_frames = 0 ) : scope = get_parent_scope_from_var ( name , global_ok = global_ok , skip_frames = skip_frames + 1 ) if not scope : return default if name in scope . locals : return scope . locals . get ( name , default ) return scope . globals . get ( name , default )
python get parent scope of function
Directly gets a variable from a parent frame - scope .
def get_parent_var(name, global_ok=False, default=None, skip_frames=0):
    """
    Directly gets a variable from a parent frame-scope.

    Returns
    --------
    Any
        The content of the variable found by the given name, or None.
    """

    scope = get_parent_scope_from_var(name, global_ok=global_ok, skip_frames=skip_frames + 1)

    if not scope:
        return default

    if name in scope.locals:
        return scope.locals.get(name, default)

    return scope.globals.get(name, default)