1

How do we set multiple breakpoints in Python using IPython, so that for example we stop at line 4 and line 100?

Also, can we change our mind and set extra breakpoints while already in debugging?

pzp
  • 6,249
  • 1
  • 26
  • 38
Kenny
  • 1,902
  • 6
  • 32
  • 61
  • Possible duplicate of [Breakpoint-induced interactive debugging of Python with IPython](http://stackoverflow.com/questions/14635299/breakpoint-induced-interactive-debugging-of-python-with-ipython) – Ajeet Shah May 25 '16 at 12:00
  • 1
    The question you mentioned seems to allow either only 1 breakpoint, either stepping line by line. I am interested in stopping at multiple locations, skipping the rest in between. – Kenny May 25 '16 at 12:30

1 Answers1

1

iPython provides IPython.core.debugger.Tracer debugger class which can be used to debugging.

Let's say I have below code written in myScript.py:

from IPython.core.debugger import Tracer
zz = Tracer()

print "iPython"
zz()
print "is a"
print "command shell"
zz()
print "for"
print "interactive computing"
print "in"
print "multiple programming languages"
print "including"
print "Python"

As you can see I have set 2 breakpoints in the script from the beginning at Line 5 and 8. Below, I am running this script and will be setting 2 more breakpoints at line 12 & 13.

$ ipython myScript.py
iPython
> /home/user/Documents/myScript.py(6)<module>()
      4 print "iPython"
      5 zz()
----> 6 print "is a"
      7 print "command shell"
      8 zz()

ipdb> break 12
Breakpoint 1 at /home/user/Documents/myScript.py:12
ipdb> break 13
Breakpoint 2 at /home/user/Documents/myScript.py:13

Also, when inside debugging, you can use commands c for continue and n for next step. Hopefully, it helps you.

Ajeet Shah
  • 18,551
  • 8
  • 57
  • 87
  • Thanks. What seems strange for me is why such a common language misses something such fundamental of a debugger and noone seems to bat an eye from what I googled. – Kenny May 31 '16 at 13:57