3

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/test.py(4)<module>()
-> astring = input("input here: ")

How can I input when debugging?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for pointing it out. Actually I was using Python 3. I will edit the question.
0

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.

3 Comments

Thanks for help. I used old error after updated the script. The question has been corrected now. When entering n, it returns same error with "abc" replaced by "n".
@WangXiaojie No ... you're either not using python 3 (else something has overwritten your input function). On python 3: python3 -c "x = input('input here:')" works while python2.7 -c "x = input('input here:')" leads to a NameError: .... Perhaps you should do input sys; print(sys.version) and see what you're running?
@donkopotamus: You are right! Thank you so much! I was using "pdb test.py" to try out pdb, where "test.py" has a "#!/usr/bin/python3". I took as granted it was using python3!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.