python python转储变量异常

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python python转储变量异常相关的知识,希望对你有一定的参考价值。

# 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)

以上是关于python python转储变量异常的主要内容,如果未能解决你的问题,请参考以下文章

Python JSON转储/附加到.txt,每个变量都在新行

如何循环 python 读取一组 HTML 文件并转储到 JSON

Python UnboundLocalError 异常

线性同余生成器的浮点异常(核心转储)

Python常见异常

python0.10-----变量作用域和异常