Skip to Content
Intuitive Python
book

Intuitive Python

by David Muller
May 2021
Intermediate to advanced
142 pages
3h 37m
English
Pragmatic Bookshelf
Content preview from Intuitive Python

Investigating with pdb Breakpoints

Python includes a built-in debugger called pdb.[20] pdb allows you to halt your program’s execution on any given line and use an interactive Python console to inspect your program’s state. Since pdb is a built-in part of Python, you can import and use pdb at anytime without running additional external executables other than your program.

To add a breakpoint to your program, pick a target line and then add import pdb; pdb.set_trace() on that line. Up until now, we’ve been typing and/or pasting code into Python’s interactive console, but for this example try running the following example code by saying python3 pdb_example.py:

1: def​ ​get_farm_animals​():
2:  farm = [​"cow"​, ​"pig"​, ​"goat"​] ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pythonic Programming

Pythonic Programming

Dmitry Zinoviev
Python for Geeks

Python for Geeks

Muhammad Asif

Publisher Resources

ISBN: 9781680508635Errata Page