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?

2
  • Possible duplicate of Breakpoint-induced interactive debugging of Python with IPython Commented May 25, 2016 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. Commented May 25, 2016 at 12:30

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.