простой вопрос: в python3 env, почему нельзя запустить простую печать? - PullRequest
0 голосов
/ 21 апреля 2020
print("hello", end="")

вывод:

[Running] python -u "/home/a/code/projects/project1.py"
  File "/home/a/code/projects/project1.py", line 1
    print("hello", end="")
                      ^
SyntaxError: invalid syntax

настройки. json

{
    "python.linting.pylintEnabled": false,
    "python.linting.enabled": true,
    "python.linting.flake8Enabled": true,
    "python.linting.pydocstyleEnabled": false,
    "python.pythonPath": "/usr/bin/python3.6"
}

выяснил, почему код запускается на более старой версии python в vscode. .. не могу понять.

1 Ответ

3 голосов
/ 21 апреля 2020

Это потому, что вы используете Python 2:

Python 2.7.16 (default, Oct 10 2019, 22:02:15) 
[GCC 8.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello", end="")
  File "<stdin>", line 1
    print("hello", end="")
                      ^
SyntaxError: invalid syntax

В Python3 этого не произойдет:

Python 3.7.3 (default, Dec 20 2019, 18:57:59) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello", end="")
hello>>> 
...