Traceback (most recent call last):
File "p.py", line 1, in <module>
x = input("hello")
File "<string>", line 0
SyntaxError: unexpected EOF while parsing
当我把以下代码输入到我的脚本中时,我得到了这个错误。
x = input("press enter to continue")
当我输入以下代码时也是如此
input("press enter to continue")
再输入这个的时候也是这样
input('press enter to continue')
我在Chrome acer上运行linux测试版,用的是python 3,到底出了什么问题?
我相信你使用的是Python 2,而不是Python 3。替换 input
与 raw_input
:
x = raw_input("press enter to continue")
这就是为什么我相信你使用的是Python 2。我用Python 3进行的测试(注意没有错误)。
Python 3.7.6
Type "help", "copyright", "credits" or "license" for more information.
>>> x = input("press enter to continue")
press enter to continue
>>>
然后我看到了和你用Python 2时一样的错误。
Python 2.7.17
Type "help", "copyright", "credits" or "license" for more information.
>>> x = input("press enter to continue")
press enter to continue
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
>>> x = raw_input("press enter to continue")
press enter to continue
>>>
试试 raw_input() 而不是 input()