-
Book Overview & Buying
-
Table Of Contents
Python Automation Cookbook - Third Edition
By :
Python has a built-in debugger called pdb. Stopping the execution of the code at any point is possible by setting a breakpoint. A breakpoint will stop the execution and jump into command-line mode. From the command line, the current status can be analyzed using any introspection available. Given that Python is interpreted, any new code can be executed from this stage. This is very flexible and allows you to create flexible breakpoints and change the current state to analyze the behavior of the program.
Let's see how to do it.
Download the debug_algorithm.py script, available from GitHub: https://github.com/PacktPublishing/Python-Automation-Cookbook-Third-Edition/blob/main/ch16/debug_algorithm.py.
In the next section, we will analyze the execution of the code in detail. The code checks whether numbers fulfill certain criteria:
def valid(candidate):
if candidate <= 1:
return False
lower = candidate - 1
while lower >...