【发布时间】:2013-05-13 14:28:40
【问题描述】:
我有一个字符串变量test,在 Python 2.x 中可以正常工作。
test = raw_input("enter the test")
print test
但在 Python 3.x 中,我会这样做:
test = input("enter the test")
print test
输入字符串sdas,我收到一条错误消息
Traceback (most recent call last):
File "/home/ananiev/PycharmProjects/PigLatin/main.py", line 5, in <module>
test = input("enter the test")
File "<string>", line 1, in <module>
NameError: name 'sdas' is not defined
【问题讨论】:
-
在 python3 中编写代码时,我在使用带有 python2 的终端时遇到了同样的问题
-
您的
print test语句不是 Python 3.x:它应该是print(test)。事实上,python 正在尝试将 test 作为命令进行评估。
标签: python python-3.x string input eval