Skip to content

Instantly share code, notes, and snippets.

@brydavis
Last active July 9, 2019 23:35
Show Gist options
  • Save brydavis/1db12de0d4fd74927b5910ff0ad26387 to your computer and use it in GitHub Desktop.
Save brydavis/1db12de0d4fd74927b5910ff0ad26387 to your computer and use it in GitHub Desktop.
Quick and Dirty Notes on Using the Python Debugger

Python Debugger in Five Minutes

This doc intends to provide basic understanding / skill to use the Python Debugger (PDB).

There's certainly more to the debugger than what's below. This just provides quick and dirty info.

Run the Debugger

Open a terminal / command line and navigate to the directory containing the main file you want to debug.

Run the following line.

python -m pdb some_file.py

Quick breakdown. -->

python is for Python

-m is a shell flag that tells Python to use whatever module that follows when running the script

pdb is the module that Python will use when executing the script

some_file.py is the name of the script... likely, your file will be called something different.

Navigating the Debugger

Now, you should be in debugger mode. What you see will depend on your some_file.py, however it should look like the first row of that file along with a (pdb) prompt.

Here are some quick codes to know.

n stands for next.

s stands for step in

until

ll stands for long list and shows where you are in the script

pp for pretty print the value of an expression

b set a break point

Exiting the Debugger

If you finish your debugging before the script finishes, just type exit at the prompt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment