如何从 python 调试器 pdb 输入

how to input from python debugger pdb

这个问题可能很简单,但我是 Python 的新手。这个问题最好用下面的简单例子来说明。我正在使用 pdb 调试以下脚本(它是 python 3):

astring = input("input here: ")

当进入上一行时,我得到以下提示并键入 "abc"

input here: abc

但是无论我从键盘输入什么,都会出现错误,例如

NameError: "name 'abc' is not defined"
> /home/wang/tmp/test.py(4)<module>()
-> astring = input("input here: ")

调试时如何输入?非常感谢!

您在 Python 上使用的函数不正确 2. 使用 raw_input rather than input

看来输入的"abc"算是评价了。但是,您的程序是输入的("input here "),但是您给出的示例是 "input here:" 并且 pdb 的输出显示 "input a line:",我不知道它们是否是同一个程序,因为这些差异。尝试输入 n(用于下一行代码)而不是 abc,看看会发生什么。