2013-07-08 340 views
-2

我使用API​​的raw_input在Python 2.7中的raw_input蟒蛇2.7

我做的:

mass_storage_choice = raw_input("Have you enabled USB mass storage on the phone Yes or No?"); 

我得到:

Traceback (most recent call last): 
    File "C:\tools\ide\juno\eclipse\plugins\org.python.pydev_2.7.3.2013031601\pysrc\pydevd_comm.py", line 765, in doIt 
    result = pydevd_vars.evaluateExpression(self.thread_id, self.frame_id, self.expression, self.doExec) 
    File "C:\tools\ide\juno\eclipse\plugins\org.python.pydev_2.7.3.2013031601\pysrc\pydevd_vars.py", line 376, in evaluateExpression 
    result = eval(compiled, updated_globals, frame.f_locals) 
    File "<string>", line 1, in <module> 
NameError: name 'Y' is not defined 

任何想法,为什么?

+3

这个错误发生在用户键入某个东西并提交之后,还是之后?如果事后发生,用户输入并提交了什么? – Kevin

+1

这个问题可能是因为你尝试在某处使用'mass_storage_choice' var,因为原来的raw_input调用按预期工作 –

+1

[pydev interactive console and raw \ _input](http:// stackoverflow。 com/questions/11138304/pydev-interactive-console-and-raw-input) – interjay

回答

0

如果您在代码中使用if ... then循环,请确保您实际上是将Y放在单引号中。就像这个'Y'。因为我感觉您正在处理Y输入,对我来说,意味着是的。如果我错了,请纠正我。

0

一旦您从用户处获得输入,将输入传递给应该工作的变量。