Import & Trace
To start the debugger, find the troubling lines in your code, and before it type in the following:
... import pdb; pdb.set_trace() ...
Commands
After you run your app, it will halt at that particular line to enable you give pdb commands:
> /home/treehouse/workspace/buggy.py(6)<module>() -> del my_list[3] (pdb)
There are many pdb commands that can help you debug your code and find why it is not working as it should:
- help – Prints the list of available commands.
- help next – Prints help about the next command.
- help pdb – Displays the full documentation
- (n)ext – Runs the next line
- (c)ontinue – Runs the rest of the program
- More commands at: https://docs.python.org/3/library/pdb.html
You can run python commands to check how the values are changing in your code.
Don’t forget to remove the pdb line of code from your code after you finish fixing your app.