输入

时间:2017-01-30 01:11:28

标签: python python-2.7 python-3.x input pycharm

enter image description here我有这个测试代码:

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项目中,解释器与运行配置不同。 要设置运行配置 - 请使用运行 - &gt;编辑配置,然后选择python解释器。

您也可以

import sys
print(sys.version) 

打印运行时版本

1 个答案:

答案 0 :(得分:1)

似乎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