b = 2
1 / 0
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)
For python is there a way to print variables scope from context where exception happens?