【问题标题】:ipdb commands obscured by variablesipdb 命令被变量遮挡
【发布时间】:2016-10-24 17:24:16
【问题描述】:

当我尝试使用 ipdb 调试此示例脚本时:

n = 1
next = 1
print('end')

我无法执行第 3 行,因为 python 变量掩盖了 pdb 命令:

$ ipdb test.py
> /tmp/test.py(1)<module>()
----> 1 n = 1
      2 next = 1
      3 print('end')

ipdb> next
> /tmp/test.py(2)<module>()
      1 n = 1
----> 2 next = 1
      3 print('end')

ipdb> next
> /tmp/test.py(3)<module>()
      1 n = 1
      2 next = 1
----> 3 print('end')

ipdb> next
1
ipdb> n
1
ipdb> !n
1
ipdb> !next
1

当两个命令 (n/next) 都不再被识别时,我该如何继续执行我的代码? (假设 s/step 也被变量所掩盖)。

到目前为止我尝试了什么:

  • 使用 ipdb3 而不是 ipdb - 同样的问题(可能是因为在我的情况下 ipdb 链接到 ipdb3 :))
  • 使用 pdb - 它有效! n/next 命令移至下一行,而不是显示 python 变量。我的 ipdb 有什么问题?
  • !!n 缓解了这个问题 - 它运行 next 的 ipdb 版本。如果我能alias n !!n 然后反复使用Enter 执行它,我的问题就解决了。但是Enter 只显示变量n 而不是运行别名n(应该解析为!!n

我正在使用

  • Manjaro Linux 16.10
  • Python 3.5.2 :: Anaconda 4.2.0(64 位)
  • ipdb (0.10.1)
  • ipython (5.1.0)
  • ipython-genutils (0.1.0)
  • 我没有 ~/.pdbrc 文件

编辑

此问题由以下人员修复:https://github.com/ipython/ipython/pull/10050

【问题讨论】:

  • 使用pdb3 您的示例按预期工作。重复next 逐步执行程序并重新启动它,而!next 显示变量的值。无法在 cpython 的 pdb 中重现。
  • 我在我的 linux 机器上安装了python3-ipdb,它也在那里工作。 next 始终被视为命令,!next 显示变量的值。
  • 我在帖子中添加了我的 python/ipdb/ipython 版本。也许它会有所作为。
  • !!n 应该强制它运行命令而不是显示变量。我认为!n 强制它把它当作一个变量,n 猜测。
  • 我创建了一个拉取请求来解决您面临的空行问题。 github.com/ipython/ipython/pull/10035

标签: python debugging ipython pdb ipdb


【解决方案1】:

2016 年 12 月 14 日更新:

最后 iPython 团队决定revoke this design


您的问题的解决方案是使用!! 语句强制标准行为。

> /home/v-zit/test.py(1)<module>()
----> 1 n = 1
      2 next = 11
      3 print('end')

ipdb> n
> /home/v-zit/test.py(2)<module>()
      1 n = 1
----> 2 next = 11
      3 print('end')

ipdb> n
1
ipdb> !!n
> /home/v-zit/test.py(3)<module>()
      1 n = 1
      2 next = 11
----> 3 print('end')

ipdb> next
11
ipdb> !!next
end
--Return--
None
> /home/v-zit/test.py(3)<module>()
      1 n = 1
      2 next = 11
----> 3 print('end')

ipdb>

参考:

https://github.com/ipython/ipython/pull/9449

https://github.com/ipython/ipython/pull/10050

【讨论】:

  • 我不认为del n 是一种解决方法 - 它会破坏程序正在使用的 python 变量,所以它会在读取它时崩溃。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-07
  • 1970-01-01
  • 2023-01-27
  • 2011-11-12
  • 2014-02-13
相关资源
最近更新 更多