How to get tab completion in PDB

A common technique to debug in Python is to add this line at a place which you want to observe:

import pdb; pdb.set_trace();

When you run the Python code and the interpreter hits this line, it drops you into a Python debugger prompt. You can inspect local variables and step through code from here.

An irritating problem here is that this PDB prompt does not offer tab completion. So, you have to type out entire variable, class and method names by yourself without any aid. Thankfully, here is a method to add tab completion feature to this PDB prompt.

Create a .pdbrc in your home directory and add these lines to it:

# Enable tab completion                                                         
import rlcompleter                                                              
import pdb                                                                      
pdb.Pdb.complete = rlcompleter.Completer(locals()).complete

Tried with: Python 3.5.1 and Ubuntu 16.04

One thought on “How to get tab completion in PDB

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.