some ipython love for your debugging experience
Like always, make sure first that all dependecies are installed. In this case
its ipython 1. Install it with pip install ipython or easy_install ipython.
Now put the following file in ipdb.py somewhere in your PYTHONPATH (for me
its ~/.local/lib/python2.6/dist-packages/ipdb.py):
import sys
from IPython.Debugger import Pdb
from IPython.Shell import IPShell
from IPython import ipapi
shell = IPShell(argv=[''])
def set_trace():
ip = ipapi.get()
def_colors = ip.options.colors
Pdb(def_colors).set_trace(sys._getframe().f_back)
Know you can use in your code the following snippet:
import ipdb; ipdb.set_trace();
This will bring up ipython's debugger instead of the old pdb prompt. Test it out! It's so cool to have code completion while debugging.
1 In case you don't know what ipython is, check their out homepage and try
to run ipython in your console after installing it. It's definitly worth exploring. (For those
who really don't know what it is: its a fancy, more feature rich python
console).
Update
As Andrey mentioned in the comments: there is an easier way now to
setup ipdb in your PYTHONPATH. Just install the ipdb package from the
PyPI: pip install ipdb

Comments ¶
blog comments powered by Disqus