17
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?

4
  • 1
    @ShinTakezou: if that works fine for you, you're not using Python 2.5. Commented May 9, 2013 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. Commented May 10, 2013 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". Commented May 10, 2013 at 11:20
  • 2
    If everyone would just read the manual, and could work out which sections of which manual to read, 90% of SO would evaporate. ;) Commented Jul 2, 2013 at 4:12

1 Answer 1

48

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.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.