I have a file called foo.py. In that file I have a bunch of functions and I would like to debug one of them, called foo.bar by setting a breakpoint but not hardcoding it using set_trace. I am working in an IPython console and I know there is a %debug magic function that can be used for this purpose with the syntax:
%debug [--breakpoint FILE:LINE]
So I try
%debug --breakpoint foo.py:10
to set the breakpoint at line 10. However, how do I actually execute the code then so that IPython recognizes the breakpoint? Doing
import foo
foo.bar()
does not work as the breakpoint is simply skipped.
The way to do this:
from foo import bar
%debug --breakpoint /path/to/foo.py:10 bar()
This will import bar into the namespace and run it with the breakpoint on line 10 of the module.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With