【问题标题】:Debug Python Script Using Multiple Breakpoints in IPython在 IPython 中使用多个断点调试 Python 脚本
【发布时间】:2016-05-20 12:55:43
【问题描述】:

我们如何在 Python 中使用IPython 设置多个断点,例如在第 4 行和第 100 行停止?

另外,我们可以在调试时改变主意并设置额外的断点吗?

【问题讨论】:

标签: python debugging ipython breakpoints


【解决方案1】:

iPython 提供了IPython.core.debugger.Tracer 调试器类,可用于调试。

假设我有以下用myScript.py编写的代码:

from IPython.core.debugger import Tracer
zz = Tracer()

print "iPython"
zz()
print "is a"
print "command shell"
zz()
print "for"
print "interactive computing"
print "in"
print "multiple programming languages"
print "including"
print "Python"

如您所见,我从第 5 行和第 8 行开始在脚本中设置了 2 个断点。下面,我正在运行此脚本,并将在第 12 行和第 13 行再设置 2 个断点。

$ ipython myScript.py
iPython
> /home/user/Documents/myScript.py(6)<module>()
      4 print "iPython"
      5 zz()
----> 6 print "is a"
      7 print "command shell"
      8 zz()

ipdb> break 12
Breakpoint 1 at /home/user/Documents/myScript.py:12
ipdb> break 13
Breakpoint 2 at /home/user/Documents/myScript.py:13

另外,在内部调试时,您可以使用命令c 继续,使用命令n 进行下一步。希望对您有所帮助。

【讨论】:

  • 谢谢。对我来说似乎很奇怪的是,为什么这样一种通用语言会遗漏调试器的一些基本功能,而我在谷歌上搜索的内容似乎没有人不注意。
猜你喜欢
  • 2023-03-27
  • 1970-01-01
  • 1970-01-01
  • 2013-01-16
  • 1970-01-01
  • 2020-11-25
  • 2018-12-23
  • 1970-01-01
  • 2012-07-29
相关资源
最近更新 更多