August 2018
Intermediate to advanced
366 pages
10h 14m
English
If you want to stop code execution at a specific point and interactively move it forward while checking how your variables change and what flow the execution takes, you just want to set a tracing point where you want to stop, so that you will enter an interactive session in the shell where your code is running:
def divide(x, y):
print('Going to divide {} / {}'.format(x, y))
# Stop execution here and enter the debugger
import pdb; pdb.set_trace()
return x / y
Now, if we call the divide function, we will enter an interactive debugger that lets us see the value of x and y and move forward with the execution:
>>> print(divide(3, 2)) Going to divide 3 / 2 > ../sources/devtools/devtools_01.py(4)divide() -> return x / y (Pdb) x 3 ...