1 of 8

Debugging with ipython and ipdb

import ipdb; ipdb.set_trace() # BREAKPOINT

2 of 8

Make sure you have setuptools installed

  • http://pypi.python.org/pypi/setuptools/
  • Try to run `which easy_install`
  • Should return something like:�/usr/local/share/python/easy_install

3 of 8

Install ipython and ipdb

  • sudo easy_install ipython
  • sudo easy_install ipdb
  • Windows installers can be found here:
    • http://pypi.python.org/pypi/ipython
    • also install pyreadline: http://pypi.python.org/pypi/pyreadline/1.7.1

4 of 8

Place a breakpoint in your code

print 'Hello World!'

my_var = 10 / 3

import ipdb; ipdb.set_trace() # BREAKPOINT

print my_var

5 of 8

Run your code

python my_project.py

6 of 8

Use ipdb

  • ? for "help"
  • ? s for "help for command s"
  • l for "some more context"
  • s for "step into"
  • n for "step over"
  • c for "continue to next breakpoint"

7 of 8

Sample program with a bug

  • http://bit.ly/buggy-class
  • Download "buggy.py"
  • Run the program:
    • python buggy.py Django
  • It should return the version of Django
  • But it does not
  • Place a breakpoint at line 45
  • Step through it and fix it :)

8 of 8

Hint: Use pprint

import pprint

pprint.pprint(some_variable)