pylint says "Unnecessary parens after %r keyword"

python, python-2.7, python-3.x

Solution

To make pylint aware that you want to use the new print statement and not put erroneous brackets simply use

from __future__ import print_function

at the beginning of your script. This has also the advantage that you always need to use `print(...)` instead of `print ...`. Accordingly, your program will throw a `SyntaxError` in case you fall back to the old syntax.

Be aware that this does not work in python 2.5 or older. But since you use 2.6 and 2.7, there should be no problem.

Problem

After my first CodeReview Q - I got tip in answer: Your code appears to be for Python 2.x. To be a bit more ready for a possible future migration to Python 3.x, I recommend to start writing your print ... statements as print(...) Thus, in my following code (I'm using Python 2.6 and 2.7 on my boxes) I always us `()` for `print`: ``` print('Hello') ``` Today I first time test my code with PyLint, and it says: C: 43, 0: Unnecessary parens after 'print' keyword (superfluous-parens) Which explained here. So - does `print(str)` is really incorrect, or I can disregard this PyLint messages?

Original source

Related problems