Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting started with the Python debugger, pdb [closed]

Tags:

python

pdb

I want to add pdb—the Python debugger—to my toolbox. What's the best way to get started?

like image 578
Matthew Rankin Avatar asked Nov 19 '10 19:11

Matthew Rankin


People also ask

How do I use pdb debugger in Python?

Starting Python Debugger To start debugging within the program just insert import pdb, pdb. set_trace() commands. Run your script normally, and execution will stop where we have introduced a breakpoint. So basically we are hard coding a breakpoint on a line below where we call set_trace().

How do I get out of pdb mode?

Whenever you want to leave the pdb console, type the command quit or exit . If you would like to explicitly restart a program at any place within the program, you can do so with the command run .

How do I start debugging in Python?

Basic debugging If you're only interested in debugging a Python script, the simplest way is to select the down-arrow next to the run button on the editor and select Debug Python File in Terminal.

How do you set a breakpoint in Python pdb?

It's easy to set a breakpoint in Python code to i.e. inspect the contents of variables at a given line. Add import pdb; pdb. set_trace() at the corresponding line in the Python code and execute it. The execution will stop at the breakpoint.


1 Answers

Here's a list of resources to get started with the Python debugger:

  1. Read Steve Ferb's article "Debugging in Python"
  2. Watch Eric Holscher's screencast "Using pdb, the Python Debugger"
  3. Read the Python documentation for pdb — The Python Debugger
  4. Read Chapter 9—When You Don't Even Know What to Log: Using Debuggers—of Karen Tracey's Django 1.1 Testing and Debugging.
like image 83
4 revs, 2 users 97% Avatar answered Oct 15 '22 15:10

4 revs, 2 users 97%