最簡單的方法是在代碼中定義一個調用someFunc()並打印回溯然後從Pdb中調用它的函數。
或者,您可以爲自己打印回溯。鑑於此源代碼:
def foo(a):
pass
def bar(b):
foo(b, 2)
def some_func():
bar(3)
if __name__=='__main__':
import pdb
pdb.set_trace()
那麼我們可以這樣做:
C:\temp>test.py
--Return--
> c:\temp\test.py(12)<module>()->None
-> pdb.set_trace()
(Pdb) import traceback
(Pdb) exec "try: some_func()\nexcept: traceback.print_exc()"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\temp\test.py", line 8, in some_func
bar(3)
File "C:\temp\test.py", line 5, in bar
foo(b, 2)
TypeError: foo() takes exactly 1 argument (2 given)
(Pdb)
有沒有什麼辦法來自動做到這一點? – 2013-12-04 14:44:12