(python) ERROR: attempted use of x = input("string") causes errors
(python) ERROR: attempted use of x = input("string") causes errors
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')
我 运行 linux 在 chrome acer 上 linux beta。它使用 python 3. 出了什么问题?
尝试 raw_input() 而不是 input()
我相信您使用的是 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
>>>
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')
我 运行 linux 在 chrome acer 上 linux beta。它使用 python 3. 出了什么问题?
尝试 raw_input() 而不是 input()
我相信您使用的是 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
>>>