Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 276
Georg Gutsche Avatar asked Feb 05 '18 16:02

Georg Gutsche


People also ask

How do I fix python interpreter in VS Code?

In VS Code, open the Settings with (Ctrl+,) then search settings for "Interpreter." There will an option for "Python: Default Interpreter Path." Set the location of your python.exe file.

How do I fix VS Code errors?

Use Quick Actions to fix or refactor code Or, when your cursor is on the line with the colored squiggle, press Ctrl+. or select the light bulb, error light bulb, or screwdriver icon in the margin. You'll see a list of possible fixes or refactorings you can apply to that line of code.

How do you show errors in VS Code?

You can click on the summary or press Ctrl+Shift+M to display the PROBLEMS panel with a list of all current errors. If you open a file that has errors or warnings, they will be rendered inline with the text and in the overview ruler.

Why my VS Code is not showing errors?

This is because the C/C++ IntelliSense, debugging, and code browsing extension does not know about the current project. Navigate to View | Command Palette, enter and select C/C++ Build and debug active file: Select Project, and then select the correct project that you want to work with.


1 Answers

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
like image 86
jjabba Avatar answered Sep 22 '22 11:09

jjabba