When at the pdb console, entering a statement which causes an exception results in just a single line stack trace, e.g.
(Pdb) someFunc()
*** TypeError: __init__() takes exactly 2 arguments (1 given)
However I'd like to figure out where exactly in someFunc
the error originates. i.e. in this case, which class __init__
is attached to.
Is there a way to get a full stack trace in Pdb?
The easiest way would be to define a function in your code that calls someFunc() and prints the traceback then call that from Pdb.
Alternatively you can print the traceback for yourself. Given this source code:
def foo(a):
pass
def bar(b):
foo(b, 2)
def some_func():
bar(3)
if __name__=='__main__':
import pdb
pdb.set_trace()
Then we can do this:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With