相关疑难解决方法(0)

PyLint消息:logging-format-interpolation

对于以下代码:

logger.debug('message: {}'.format('test'))
Run Code Online (Sandbox Code Playgroud)

pylint 产生以下警告:

记录格式插值(W1202):

在日志记录函数中使用%格式并将%参数作为参数传递当日志语句的调用形式为"logging.(format_string.format(format_args ...))"时使用.此类调用应使用%格式,但通过将参数作为参数传递,将插值留给日志记录功能.

我知道我可以关掉这个警告,但我喜欢理解它.我假设使用format()是打印输出语句的首选方法pylint.为什么记录器语句不适用?

python pylint python-3.x

128
推荐指数
4
解决办法
3万
查看次数

Pylint 日志记录不懒惰的问题?

filename_format = prefix + startdate.strftime('%Y%m%d') + '_' + enddate.strftime('%Y%m%d')
LOGGER.info('Filename format: ' + filename_format)
Run Code Online (Sandbox Code Playgroud)

对于以上,我得到

指定字符串格式参数作为日志函数参数(logging-not-lazy)

当我运行 pylint. 哪个部分是错误?

python pylint

2
推荐指数
1
解决办法
4159
查看次数

在python日志记录中对字符串进行惰性求值:将`%`与`.format`进行比较

这两个电话之间有什么区别:

import logging

logging.getLogger().debug('test: %i' % 42)
Run Code Online (Sandbox Code Playgroud)

logging.getLogger().debug('test: {}'.format(42))
Run Code Online (Sandbox Code Playgroud)

我们假设42在被投射到字符串(例如750万年)时会被一些长计算所取代,产生最终答案为42.

在将日志记录设置为调试的情况下,是否对前一种方法进行了延迟评估?

python string logging

0
推荐指数
2
解决办法
993
查看次数

标签 统计

python ×3

pylint ×2

logging ×1

python-3.x ×1

string ×1