pdb
To start debugging
python -m pdb test.pyIt is best to use (better than pdb)
pip install ipdb
python -m pip install ipdb
python -m ipdbor you can use:
import pdb
pdb.set_trace()or
import pdb; pdb.set_trace()Basically pdb has similart syntax like ipdb.
colab
import pdb
%pdbdebugging - How to step through Python code to help debug issues? - Stack Overflow
Debugging in Google Colab notebook
Useful commands:
b: set a breakpoint
b 11 #this would set a breakpoint at line 11
b some_function # set breakpoint at function_name
c: continue debugging until you hit a breakpoints: (step) through the coden: to go to (next) line of codel: list source code for the current file (default: 11 lines including the line being executed)u: navigate up a stack framed: navigate down a stack framep: to print the value of an expression in the current contextr: (return) execute code till it returns from the current function or hits another breakpointw: (where) Shows the stacktrace i.e. the chain of functions
that made it reach the current functiona: (arguments) List of arguments passed and its values to the functionq: (quit)Immediately stop execution and quit the debugger
You have basically two modules. pdb and ipdb
ipdb stands for interactive python debugger and is designed for colab .
ipdb
!pip install -Uqq ipdb
import ipdb%pdb onipdb.set_trace()Python
Python Libraries for Training
Python Must-Have Libraries for VScode
VSCode