编程语言
首页 > 编程语言> > python – 如何修复pylint logging-not-lazy?

python – 如何修复pylint logging-not-lazy?

作者:互联网

参见英文答案 > PyLint message: logging-format-interpolation                                    1个
我正在使用prospector来检查我的代码. Pylint返回了一个关于我的调试消息的日志记录而不是懒惰的警告.

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

标签:python,pylint
来源: https://codeday.me/bug/20190930/1835755.html