For python is there a way to print variables scope from context where exception happens? -


What is the exception where there is a way to print variable properties from the context? For example:

For example:

  def f (): a = 1b = 2 1/0 try: f () except: A ': 1, like' b ': 2} "   

You can use the function sys.exc_info () to get the last exception to your existing thread except this exception type, exception example and traceback will be a duplicate of the traceback frame. The list is backstreet by interpreter Is it used for. Try

  import sys def f (): a = 1b = 2 1/0: except f (): exc_type, exc_value, tb = sys.exc_info () If there is no TB No: prev = tb curr = tb.tb_next while not curr: prev = curr curr = curr.tb_next print.txt.tb_frame.f_locals    

Comments