inputs = list(map(int, input().split()))
print(n)
print(inputs)
当我在下面的控制台输入 3 4 时;我收到以下错误:
Traceback (most recent call last):
File "/Users/Labhesh/PycharmProjects/algotoolbox/assignment1/test.py", line 2, in <module>
inputs = list(map(int, input().split()))
File "<string>", line 1
3 4
^
SyntaxError: unexpected EOF while parsing
Process finished with exit code 1
当我从命令行运行相同的代码时,没有问题:
>> python3 test.py
>> 3 4
>> [3, 4]
我需要做一些特殊设置才能使这个简单的代码在 PyCharm 中工作吗?
编辑
似乎在pycharm项目解释器中与运行配置不一样。 要设置运行配置 - 使用运行 --> 编辑配置,然后选择 python 解释器。
你也可以这样做
import sys
print(sys.version)
打印运行时版本
最佳答案
PyCharm 可能正在使用 2.x 版本的 Python。
在 PyCharm 中使用 python 3.5 运行时:
"C:\Program Files (x86)\Python35-32\python.exe" "C:\Program Files (x86)\JetBrains\PyCharm 2016.3\helpers\pydev\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 59807 --file C:/src/testcode/test.py
pydev debugger: process 12684 is connecting
Connected to pydev debugger (build 163.10154.50)
3 4
[3, 4]
Process finished with exit code 0
在 PyCharm 中使用 Python 2.7 运行时:
C:\Python27\python.exe "C:\Program Files (x86)\JetBrains\PyCharm 2016.3\helpers\pydev\pydevd.py" --multiproc --qt-support --client 127.0.0.1 --port 59813 --file C:/src/testcode/test.py
pydev debugger: process 16920 is connecting
QSslSocket: cannot resolve SSLv2_client_method
QSslSocket: cannot resolve SSLv2_server_method
Connected to pydev debugger (build 163.10154.50)
3 4
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3\helpers\pydev\pydevd.py", line 1596, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files (x86)\JetBrains\PyCharm 2016.3\helpers\pydev\pydevd.py", line 974, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:/src/testcode/test.py", line 13, in <module>
inputs = list(map(int, input().split()))
File "<string>", line 1
3 4
^
SyntaxError: unexpected EOF while parsing
关于python - pycharm python3 输入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41927778/