Demo 2: Interactive Debugging with pdb 🐞¶
Goal¶
Use interactive debuggers to pause code, inspect variables, and step through execution.
Setup¶
- Provided
demo2-buggy-script.pywith logic errors - Insert
breakpoint()statements in the code where you want to pause
Tasks¶
- Insert
breakpoint()near the suspected bug. - Run the script with pdb:
- Use
pdbcommands: n(next line)s(step into function)p var(print variable)c(continue)- Inspect variables and program flow.
- Fix the bug. Rerun to confirm.
Expected Outcomes¶
- Students can pause code execution.
- Students can inspect and modify variables interactively.
- Students can step through code to find bugs.