Georg Gutsche
Georg Gutsche

Reputation: 492

VS Code shows an error message at print statement in python 2.7

I use VS Code Version 1.19.3 with Python 2.7 on Windows.

Recently pylint (code analyzer) shown an error message "E1601:print statement used"

But I don't know why! Can someone help me?

The print statement is correct as per my knowledge!

Is it a bug or a feature is missing?

Greetings niesel

enter image description here

Upvotes: 14

Views: 9442

Answers (3)

jjabba
jjabba

Reputation: 504

The warning originates from Pylint, which is a very helpful tool for a dynamic language with loose syntax like Python. Since you are programming in Python 2.x where print is perfectly valid, I suggest you put a file in the root of your repo named .pylintrc and use it to configure Pylint.

To disable the print warning and leave everything else to the default, enter these two lines in your .pylintrc file:

[MESSAGES CONTROL]
disable=print-statement

You will also need to tell Visual Studio Code to use your configuration file by opening your workspace or user settings and add this:

{
     "python.linting.enabled": true,
     "python.linting.pylintEnabled": true,
     "python.linting.pylintArgs": [
          "--rcfile=/path/to/.pylintrc"
     ]
}

More options

To get a good idea of available configuration options open a terminal/prompt and run this command to generate a sample configuration file:

pylint --generate-rcfile > sample_pylintrc

Upvotes: 14

Dmitriy Rabotyagov
Dmitriy Rabotyagov

Reputation: 140

The problem is, that changing from print statement to print function doesn't help much. So it seems, that it is some bug in VS Code Python module (2018.1 (01 Feb 2018)), as after this update I've found the same problem in my VS Code within my old projects

bug screenshot

I've found reffered bug on their github

PS: vscode-python has changed pylint options since 2018.1. In order to return old behavior you may disable python.linting.pylintUseMinimalCheckers option for the workspace or for the userspace.

Upvotes: 7

Jean-François Fabre
Jean-François Fabre

Reputation: 140256

it's not an error per-se, it's just PyLint complaining about those legacy statements. PyLint will also complain about missing spaces before commas, those kind of style errors.

PyLint is there to warn you about possible problems. Your code will break when running python 3, so it warns you before it happens.

Note that print is a statement in python 2.x (which explains the message), and became a function in python 3.x.

Fix it by changing to:

print("test")

Since it's not a tuple, it works fine and does exactly the same for all versions of python, and PyLint will stop complaining.

you can also get rid of PyLint altogether: Windows 10 - Visual Studio Code - removing pylint (not sure if it's a good idea)

Upvotes: 0

Related Questions