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?

jamylak
  • 128,818
  • 30
  • 231
  • 230
Deepak Dubey
  • 309
  • 1
  • 3
  • 12
  • 1
    @ShinTakezou: if that works fine for you, you're not using Python 2.5. – Wooble May 09 '13 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 '13 at 06: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 '13 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. ;) – poolie Jul 02 '13 at 04:12

1 Answers1

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.

Community
  • 1
  • 1
poolie
  • 9,289
  • 1
  • 47
  • 74