Skip to content

Instantly share code, notes, and snippets.

@mono0926
Created August 24, 2013 04:12
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save mono0926/6326015 to your computer and use it in GitHub Desktop.
Save mono0926/6326015 to your computer and use it in GitHub Desktop.
Debugging with ipython and ipdb

This is copy of Debugging with ipython and ipdb.

Debugging with ipython and ipdb

Make sure you have setuptools installed

Install ipython and ipdb

Place a breakpoint in your code

print 'Hello World!'
my_var = 10 / 3
import ipdb; ipdb.set_trace() # BREAKPOINT
print my_var

Run your code

python my_project.py

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"

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 :)

Hint: Use pprint

  • import pprint
  • pprint.pprint(some_variable)
@alphaCTzo7G
Copy link

What is the benefit of ipdb over pdb? I can run pdb through ipython as well. Is there a benefit of using ipdb in ipython?

@alphaCTzo7G
Copy link

If you have ipython, you dont need to install ipdb separately. Its already installed. https://stackoverflow.com/a/47082108/4752883

you can try it out using "import ipdb...."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment