David Abel


0. Instructions

1. Basics

2. Functions

3. Dictionaries

4. OOP

5. Modules

6. Debugging

7. Tips & Tricks

Python Tutorial

python logo

This tutorial is intended as an introduction to Python for folks with some prior programming experience.

Section 6: Debugging (no file)

Because python is an interpreted language, it can often be difficult to debug. Addiitonally, the error messages in python are notoriously unhelpful (in some cases). One method of debugging is using prints liberally until you can diagnose the issue. Python also comes equipped with the pdb (Python DeBugger).

The most basic use for pdb is to step through code. To do this, simply import the module pdb and write the command pdb.set_trace() wherever you would like to start debugging. Then, run your code as usual. When the interpreter reaches the line you called set_trace, the interpreter will stop and show you the next line to be executed, and wait for your input.

To advance to the next line, press "n".

To return to the previous "set_trace()", press "Enter".

To quit, press "q".

To print out the value of any variables, enter p at the pdb prompt followed by any variables you would like to see. For example:

(Pdb) > p list_of_ints, data, main_key

If you're running into Syntax Errors, be sure to check for colons and white-space.

< Previous Section Next Section >