【问题标题】:Logging format interpolation with multiple arguments具有多个参数的记录格式插值
【发布时间】:2021-07-04 12:10:13
【问题描述】:

pylint 产生以下警告:

记录格式插值 (W1202):

在日志记录函数中使用 % 格式并将 % 参数传递为 参数 当日志语句的调用形式为 “记录。(format_string.format(format_args ...))”。此类电话应 改用 % 格式,但将插值留给日志记录 通过将参数作为参数传递来函数。

所以正确的记录方式是:logger.error('oops caused by %s', exc)

但是如何传递多个参数呢?有类似的东西: logger.error('oops caused by %s %s')(在哪里放exc_oneexc_two?)

【问题讨论】:

    标签: python logging pylint string-interpolation


    【解决方案1】:

    你应该把它作为一个普通的位置参数传递

    logger.error('oops caused by %s %s', exc_one, exc_two)

    见函数signaturelogging.error(msg, *args, **kwargs)

    【讨论】:

      猜你喜欢
      • 2023-03-25
      • 2015-07-09
      • 2016-04-09
      • 1970-01-01
      • 2016-10-01
      • 2013-04-14
      • 1970-01-01
      • 1970-01-01
      • 2014-04-22
      相关资源
      最近更新 更多