[英]debug magic function in ipython console
I have a file called foo.py. 我有一个名为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
. 在该文件中,我有一堆函数,我想通过设置一个断点来调试其中一个名为foo.bar
,而不是使用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: 我正在IPython控制台中工作,我知道可以使用以下语法使用%debug
魔术函数:
%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? 在第10行设置断点。但是,我实际上如何执行代码,以便IPython识别断点? 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. 这会将bar
导入命名空间,并在模块的第10行上使用断点运行它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.