来自 Python input() 函数的 NameError [英] NameError from Python input() function

查看:78
本文介绍了来自 Python input() 函数的 NameError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

input_var = input ("Press 'E' and 'Enter' to Exit: ")

NameError: name 'e' is not defined

我使用的是 Python 2.5.我该如何克服这个错误?

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

推荐答案

input 读取和计算 Python 表达式.当它尝试对其求值时,它会查找未定义的变量 e,但失败了.

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.

您几乎总是想改用 raw_input.(而在 Python3 中,input 具有这种行为.)

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

或者更好的是,在 Unix 上,使用 readline 以便用户可以编辑他们的意见.

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

这篇关于来自 Python input() 函数的 NameError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆