Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

debug magic function in ipython console

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.

like image 868
Alex Avatar asked Jul 30 '26 01:07

Alex


1 Answers

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.

like image 57
Alex Avatar answered Jul 31 '26 14:07

Alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!