Using the Python debugger

A few days ago I found out that using the Python debugger is so easy, I can't believe I haven't used it before.

Import the module:

import pdb

Set a breakpoint somewhere in your code:

def some_function(self, x, y, z):

Run your program. Now every time 'some_function' is called, the Python interpreter will break. At this point you could:

  • type x to inspect the argument passed to the x parameter
  • hit the 'n' button to skip over the next line of code
  • hit the 'c' button to resume the program
  • hit the 'h' button to get help

Easy enough?

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.