Using the Python debugger

Another very effective way of debugging Python is to use the Python debugger: pdb. Instead of using it directly though, you should definitely check out the pdbpp library. pdbpp augments the standard pdb interface by providing some convenient tools, my favorite of which is the sticky mode, which allows you to see a whole function while you step through its instructions.

There are several different ways to use this debugger (whichever version, it's not important), but the most common one consists of simply setting a breakpoint and running the code. When Python reaches the breakpoint, execution is suspended and you get console access to that point so that you can inspect all the names, and so on. You can also alter ...

Get Learn Web Development with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.