【发布时间】:2020-11-07 11:48:23
【问题描述】:
当我尝试运行这个简单的脚本时出现错误:
input_variable = input("Enter your name: ")
print("your name is" + input_variable)
假设我输入“dude”,我得到的错误是:
line 1, in <module>
input_variable = input("Enter your name: ")
File "<string>", line 1, in <module>
NameError: name 'dude' is not defined
我正在运行 Mac OS X 10.9.1,并且正在使用安装 Python 3.3 时附带的 Python Launcher 应用程序来运行脚本。
【问题讨论】:
-
你确定是 Python 3.3 吗?我希望
input会以这种方式行事,但仅限于 2.7。当您从命令提示符运行python --version时,它会说什么?或者,如果您在脚本开头写import sys; print(sys.version)会怎样? -
你运行的不是 Python 3。你运行的是 Python 2,不知何故(我不熟悉这个“Python Launcher”应用)
-
将
import sys作为第一行,print(sys.version_info)作为第二行,以确定您使用的版本。 -
我按照凯文所说的做了,它是 2.7.5 版!我不确定如何。我下载并安装了 3.3 版,在我的应用程序文件夹中有一个名为“Python 3.3”的文件夹,该文件夹中有一个名为“Python Launcher”的应用程序,我通过将脚本拖放到 Python Launcher 应用程序上来运行我的脚本.为什么我在使用 3.3 启动器应用时还在使用 2.7?
-
@chillpenguin:查看 Python 启动器的首选项对话框。显然,它并不默认运行安装它的版本,这是......愚蠢的。 (我自己从未使用过它;我发现使用终端更好......)
标签: python python-2.7 input nameerror