Debugging In Python – Dilemma #2

Mon 28 July 2008 by Garry Bodsworth

The next stage in Python development is “how do I debug”.

I’m at the stage where I keep adding print statements into the code to spot code flows and inspect values (which is nice because you can print more or less anything). But this is an extremely archaic way of approaching it, especially in this day and age…

Apparently there is a PDB module (there is another nice article here) but it seems to require code changes (an import and where you want to break), not a great deal of fun, especially if you accidentally leave some of this code in. It’s quite odd that it is not immediately apparent how to have breakpoints or to inspect data values.

Also, because there is a lack of a sanity checker by default you have to run your code and exercise the code paths to test your code. The good thing is that there are a number of programs to help with that, PyLint, PyChecker and PyFlakes, so it is not much of a worry.

PyDev has an interactive debugger so this will require much more investigation because it also can integrate PyLint for some error checking.