How to fix pylint logging-not-lazy?

PythonPylint

Python Problem Overview


I am using prospector to examine my code. Pylint returned a logging-not-lazy warning about my debug message.

Line: 31
  pylint: logging-not-lazy / Specify string format arguments as logging function parameters (col 16)   Line: 42
  pylint: logging-not-lazy / Specify string format arguments as logging function parameters (col 12)

My code is:

logging.debug("detect mimetypes faild because %s" % e )

How do I fix logging-not-lazy in pylint?

Python Solutions


Solution 1 - Python

This means, that you should rewrite your code as:

logging.debug("detect mimetypes faild because %s", e)

According to https://docs.python.org/2/library/logging.html

> **Logger.debug(msg, *args, kwargs) > > ... Logs a message with level DEBUG on this logger. The msg is the message format string, and the args are the arguments which are merged into msg using the string formatting operator. (Note that this means that you can use keywords in the format string, together with a single dictionary argument.) ...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionValeriy SolovyovView Question on Stackoverflow
Solution 1 - PythonZada ZorgView Answer on Stackoverflow