def get_variable_from_exception(exception, variable_name):
    """
    Grab the variable from closest frame in the stack
    """
    for frame in reversed(trace()):
        try:
            # From http://stackoverflow.com/a/9059407/6461688
            frame_variable = frame[0].f_locals[variable_name]
        except KeyError:
            pass
        else:
            return frame_variable
    else:
        raise KeyError("Variable '%s' not in any stack frames", variable_name)
def get_variable_from_exception ( exception , variable_name ) : for frame in reversed ( trace ( ) ) : try : frame_variable = frame [ 0 ] . f_locals [ variable_name ] except KeyError : pass else : return frame_variable else : raise KeyError ( "Variable '%s' not in any stack frames" , variable_name )
Grab the variable from closest frame in the stack