次のスニペット:
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
の呼び出しを含む完全なスタックトレースが必要な場合は、何を使用すればよいですか?
重要な場合はPython2.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