Classical Way — PDB

We saw print statements helps us find relevant information regarding the issues, but these tools aren’t enough to find every root cause. When we need something more powerful, it’s time to try Python’s built-in interactive debugger.

pdb module provides an interactive debugging environment for Developers to debug Python programs (including jupyter notebooks). To initiate the debugger, all we have to do is import the pdb built-in module and run its set_trace function.

import random

def find_max (values):

max = 0

import pdb; pdb.set_trace()

for val in values:

if val > max:

max = val

return max

find_max(random.sample(range(100), 10))

Demo:

Advantages:

Dynamic.

No installation required.

Mature (More features, good documentation, and fewer bugs).

Disadvantages:

Very scary.

Steep learning curve.

Additional Resources: