I never used Pdb much. I always thought that I had to run my whole script through the debugger, set some breakpoints through obscure commands and whatnot. But it is not the case. I can do simply this:
#!/usr/bin/env python do_some_stuff() import pdb pdb.set_trace() do_some_other_stuff()
Now you run your script as usual, and it stops at the pdb.set_trace()
line and opens up a Pdb prompt. Then you can go line by line, explore and set variable contents and find out the source of your problem. Great! This approach is convenient and easy to use.
You need to know just a several basic commands to be able to do quite a lot in the Pdb shell. Read this 10-minute introduction, it’s worth it: Debugging in Python
Enjoy.