LoginSignup
13
13

More than 5 years have passed since last update.

IPythonのデバッガー(ipdb)の使い方

Last updated at Posted at 2013-08-24

This is a 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)
13
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
13