notebook 中内建的pdb
在需要breakpoint的地方插入import pdb; pdb.set_trace()
,运行后会进入debugger,有一个交互界面。
def test_breakpoint_with_ipdb():
a = 1
import pdb; pdb.set_trace()
b = 2
c = 3
final = a + b + c
return final
test_breakpoint_with_ipdb()

debugger会在断点前停下,
n
执行下一行,c
执行下面所有代码。h
可以查看所有命令。
ipdb
from IPython.core.debugger import set_trace
def test_breakpoint_with_ipdb():
a = 1
set_trace()
b = 2
c = 3
final = a + b + c
return final
test_breakpoint_with_ipdb()

如果遇到报错更新一下ipython:
conda update ipython
conda update ipykernel
网友评论