NameError from Python input() function [duplicate]
Asked Answered
H

1

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?

Hoenack answered 9/5, 2013 at 8:21 Comment(4)
@ShinTakezou: if that works fine for you, you're not using Python 2.5.Predicament
@Predicament 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.Hydromedusa
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".Predicament
If everyone would just read the manual, and could work out which sections of which manual to read, 90% of SO would evaporate. ;)Intestinal
I
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.

Intestinal answered 9/5, 2013 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.