如何修复 pylint logging-not-lazy?

How to fix pylint logging-not-lazy?

我正在使用 prospector 检查我的代码。 Pylint 返回了关于我的调试消息的 logging-not-lazy 警告。

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)

我的代码是:

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

如何在 pylint 中修复 logging-not-lazy

这意味着,您应该将代码重写为:

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

根据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.) ...