# collect the variable from the caller functions
def f():
a = 1
b = 2
1/0 # trigger the exception
try:
f()
except:
exc_type, exc_value, tb = sys.exc_info()
if tb is not None:
prev = tb
curr = tb.tb_next
while curr is not None:
prev = curr
curr = curr.f_back
print(prev.tb_frame.f_globals)
# collect the variable from the caller functions
def f():
a = 1
b = 2
1/0 # trigger the exception
try:
f()
except:
exc_type, exc_value, tb = sys.exc_info()
if tb is not None:
prev = tb
curr = tb.tb_next
while curr is not None:
prev = curr
curr = curr.tb_next
print(prev.tb_frame.f_locals)