简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM