Search code examples
pythonlintstatic-code-analysis

Flag "print" statements in Python code


I don't want "print" statements in our Python modules, because we will be using a logger.

I'm trying to generate a script to check modules with pylint. However, pylint currently does not detect this as a warning or error.

I want to detect "print" invocations as an error or a warning in accordance with our internal Python programming standard.

How can I achieve this?


Solution

  • flake8 has a flake8-print plugin specifically for the task:

    flake8-print

    Check for Print statements in python files.

    DEMO:

    $ cat test.py
    s = "test"
    print s
    
    $ flake8 test.py
    test.py:2:1: T001 print statement found.