I want to stop trying to find the root of debugging by inserting a print statement and executing it over and over again.
--How to specify a breakpoint and debug --How to start the debugger when an error occurs --Applies only to specific cells --Applies to the entire notebook
I will introduce three methods.
If you know the line you want to debug, Insert the following line between the lines you want to debug.
from IPython.core.debugger import Pdb; Pdb().set_trace()
The following is an example of a break when ʻi becomes 10. You can certainly see ʻi = 10
.
If you want to start Pdb when a bug occurs somewhere.
** If you want to apply only to a specific cell **, put the following row at the beginning of the cell.
%%debug
** If you want to apply it to the entire notebook **, put the following line somewhere.
%pdb on
# %pdb off ← When you want to turn off debug detection mode
I'm intentionally raising an error when ʻi == 10`. The debugger is running properly.
Isn't it here? Please let me know if it is convenient.
command | Description |
---|---|
w | Show stack trace(where) |
n | Run until next line(next) |
c | Continue execution until next breakpoint(continue) |
q | Run to the end and finish(quit) |
d | Dive into a function(down) |
u | Get out of the function(up) |
s | Execute until the next function call(step) |
r | Run until the current function returns(return) |
Recommended Posts