如何修复 pylint 日志记录不懒惰?

我正在使用探测器检查我的代码。 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

59523 次浏览

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 ABC0 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.) ...