Debugging algorithms
There is a debugger we can run in Python using the breakpoint()
function (which is built-in). We can introduce this code into our program and insert it where we are unsure of our code. Adding breakpoint()
will then check for bugs and errors. When we run a breakpoint()
function, we'll get a pdb
output, which stands for Python Debugger. As a note, this built-in function appears in Python 3.7 and newer versions. The previous debugger for Python 3.6 and older was pdb.set_trace()
.
When we run the debugger, we can use four commands:
c
: Continues the executionq
: Quits the debugger/executionn
: Steps to the next line within the functions
: Steps to the next line in this function or a called function
Let's take a look at a code and run each of the commands outlined:
ch7_debugger.py
number = 5 number2 = 'five' print(number) breakpoint() print(number2)
Looking at this code, you can see the breakpoint()
command after...