Page

User

Problem

You'd like to include Python scripts into my .pdbrc, but only pdb commands are allowed there.

Solution

Use execfile() to run a file containing your Python code.

.pdbrc may look like this:

# .pdbrc only allows for debugger commands; you cannot insert Python
# scripts.
# To overcome this restriction, this .pdbrc executes ~/.pdbrc.py,
# which can contain arbitrary Python commands (including a call to a
# local pdbrc.py (no leading dot!) in your working directory if it
# exists).
# If ~/.pdbrc.py is missing, you get an error message (which doesn't
# hurt).
execfile(os.path.expanduser("~/.pdbrc.py"))