Python 如何修复pylint logging-not-lazy?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29147442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix pylint logging-not-lazy?
提问by Valeriy Solovyov
I am using prospector to examine my code. Pylint returned a logging-not-lazy
warning about my debug message.
我正在使用探矿者来检查我的代码。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)
My code is:
我的代码是:
logging.debug("detect mimetypes faild because %s" % e )
How do I fix logging-not-lazy
in pylint?
我如何logging-not-lazy
在pylint中修复?
采纳答案by Zada Zorg
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
根据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 theargs
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.) ...
Logger.debug(msg, *args, **kwargs)
... 在此记录器上记录一条 DEBUG 级别的消息。的
msg
是消息格式字符串,并且args
是其中使用的字符串格式化操作合并到MSG的参数。(请注意,这意味着您可以在格式字符串中使用关键字以及单个字典参数。)...