Debugging Flashcards
How to debug code
a large chunk of our time as Sr Developers is debugging our code.
Answering the question: Why doesn’t this work?
What do we expect the code to do?
What exactly is this code doing?
Recommended tools:
linting
IDEs or Editors: makes it easier for us to detect errors before we run the code
Learn to read errors:
*** There are about 15 - 20 common errors
If you see an error that you don’t recognize/understand, go to the Python documentation and learn about the error
PDB
PDB is the Python Debugger and is a built-in module in Python
PDB is extremely useful bc it allows us to interact with the code
Although print is a great quick method for debugging, the set_trace method in the PDB module is the most useful. It opens up an interactive terminal the shows us the values of any variable
in the interactive prompt:
a: returns all the arguments
w: shows the context of the current line its executing
can write code and modify variables