Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
input_var = input ("Press 'E' and 'Enter' to Exit: ")

NameError: name 'e' is not defined

I am using Python 2.5. How I can overcome this error?

share|improve this question
2  
the line works fine, very likely your problem is not there – ShinTakezou May 9 at 8:24
@ShinTakezou: if that works fine for you, you're not using Python 2.5. – Wooble May 9 at 14:32
@Wooble using python 2.5 r25:51908 (but it would be the same with 2.7) and guess: it works just fine. In fact the problem is not the line itself (but the provided input and the wrong usage of the input)... there's a rude answer for that, it's rtfm, I've just avoided that, but can I politely pour the doubt so that people may think they need to inspect the problem more deeply to get what's going on while waiting for an actual help? I did so, or so I think. Very likely, failed. Enlightening it's such a hard matter. – ShinTakezou May 10 at 6:59
1  
The whole issue is input() in Python 2. If you type e at the prompt, you will get an error, so it doesn't "work fine". – Wooble May 10 at 11:20
If everyone would just read the manual, and could work out which sections of which manual to read, 90% of SO would evaporate. ;) – poolie Jul 2 at 4:12

2 Answers

up vote 6 down vote accepted

input reads and evaluates a Python expression. When it tries to evaluate it, it looks for a variable e, which is not defined, and fails.

You almost always want to use raw_input instead. (And in Python3, input has this behaviour.)

Or, better, on Unix, use readline so the user can edit their input.

share|improve this answer
thanks for your time and link – Deepak Dubey May 9 at 9:10

you can simply use

input = raw_input
share|improve this answer
I think rebinding built-in functions is just likely to confuse people. Maybe in this case where you're rebinding it to get the py3k behavior it's ok. – poolie Jul 2 at 4:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.