以下片段:
import traceback
def a():
b()
def b():
try:
c()
except:
traceback.print_exc()
def c():
assert False
a()
产生这个输出:
Traceback (most recent call last):
File "test.py", line 8, in b
c()
File "test.py", line 13, in c
assert False
AssertionError
如果我想要完整的堆栈跟踪,包括对 a 的调用,我应该使用什么?
如果重要的话,我有 Python 2.6.6
编辑:我想获得的是相同的信息,如果我离开尝试除外,让异常传播到顶层。这个片段例如:
def a():
b()
def b():
c()
def c():
assert False
a()
产生这个输出:
Traceback (most recent call last):
File "test.py", line 10, in <module>
a()
File "test.py", line 2, in a
b()
File "test.py", line 5, in b
c()
File "test.py", line 8, in c
assert False
AssertionError