Debugging with pdb
Most of the Python developers reading this book might already be aware of the usage of python debugger (pdb). For those who are not aware of it, pdb
is an interactive source code debugger for Python programs. We can set breakpoints wherever needed, debug using single stepping at the source line level, and inspect the stack frames.
Many new developers might be of the opinion that the job of a debugger can be handled using a logger, but debuggers provide a much deeper insight into the flow of control, preserve the state at each step, and hence, potentially save a lot of development time. In this recipe, let’s have a look at what pdb
brings to the table.
Getting ready
We will use Python’s built-in pdb
module for this recipe and use it in our application from the last recipe.
How to do it…
Using pdb
is pretty simple in most cases. We just need to insert the following statement wherever we want to insert a breakpoint to inspect a certain...