Python日志记录导入不一致打印

匿名别名

使用记录器时

Import logging
logging.info(
    f"This is a  \nid: {id}", \
    f"\nclaim number: {claim_number}")

导致错误,TypeError: not all arguments converted during string formatting

print(
    f"This is a  \nid: {id}", \
    f"\nclaim number: {claim_number}")

工作良好

我想知道用记录器执行此操作最简单的方法是,有多行,所以我想按项目逐行拆分

XAMES3

我可能误解了您的意思,但是我想仅使用普通的f字符串就可以解决问题,而不是使用“ \”来分割日志记录。

尝试以下方法:

logging.info(f"This is a\nid: {id}\nclaim number: {claim_number}")

如果您只是想将日志记录跨多行,请尝试编写如下代码:

logging.info(f"This is a\nid: {id}"
             f"\nclaim number: {claim_number}"
             f"\nSome other stuff: {some_other_stuff}"
             f"\nThis method can be used even if there "
             f"is nothing to format.")

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章