如何阻止PDB每次打印最后一个变量

2024-03-29 15:47:39 发布

您现在位置:Python中文网/ 问答频道 /正文

鉴于以下互动会话:

$ python -c "import pdb; pdb.set_trace()"
--Return--
> <string>(1)<module>()->None
(Pdb) print "hello"
hello
(Pdb)
hello
(Pdb)
hello
(Pdb) pass
(Pdb)
(Pdb)

每个新的语句都会打印出hello。为什么会发生这种情况?我该如何阻止它?你知道吗


Tags: importnonehellostringreturntrace情况pass
1条回答
网友
1楼 · 发布于 2024-03-29 15:47:39

它不是“打印最后一个变量”,而是在按enter键时重复最后一个pdb命令,而不指定命令或python表达式。你知道吗

为什么会这样?嗯,因为作者认为这可能是一条有用的捷径,所以你不必一遍又一遍地重打“n”或“s”。It's actually documented转发:

Entering a blank line repeats the last command entered. Exception: if the last command was a list command, the next 11 lines are listed.

至于“如何停止”部分,我想你要么fork pdb要么创建你自己的调试器子类,但我不明白你为什么要这么做——它实际上是调试器的一个非常有用的特性(对于shell来说确实很烦人,但这不是我们在这里讨论的,是吗?)。你知道吗

相关问题 更多 >