How to input from the Python debugger (pdb)


The question is best illustrated by the following simple example. I am using pdb to debug the following script (it is Python 3):

astring = input("input here: ")

when stepping in the above line, I get the following prompt and type "abc":

input here: abc

But whatever I input from the keyboard, I get an error, e.g.,

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

How can I input when debugging?

Asked By: Wang Xiaojie



You are using the incorrect function for your purposes in Python 2. Use raw_input rather than input.

Answered By: donkopotamus

It seems that the "abc" entered is considered an evaluation. However, your program is input("input here "), but the example you give is "input here:" and the output from pdb says "input a line:".

I don’t know whether they are they same program due to these differences. Try entering n (for next line of code) instead of abc and see what happens.

Answered By: leyanpan
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.