pdb

To start debugging

python -m pdb test.py

It is best to use (better than pdb)

pip install ipdb 
python -m pip install ipdb
python -m ipdb

or you can use:

import pdb
pdb.set_trace()

or

import pdb; pdb.set_trace()

Basically pdb has similart syntax like ipdb.

colab
import pdb
%pdb

debugging - 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 breakpoint
  • s: (step) through the code
  • n: to go to (next) line of code
  • l: list source code for the current file (default: 11 lines including the line being executed)
  • u: navigate up a stack frame
  • d: navigate down a stack frame
  • p: to print the value of an expression in the current context
  • r: (return) execute code till it returns from the current function or hits another breakpoint
  • w: (where) Shows the stacktrace i.e. the chain of functions
    that made it reach the current function
  • a: (arguments) List of arguments passed and its values to the function
  • q : (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 on
ipdb.set_trace()

Python
Python Libraries for Training
Python Must-Have Libraries for VScode
VSCode