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}")

工作正常


我想知道使用记录器执行此操作的最巧妙方法是什么,有多行,所以我想按每个项目的行拆分它们


喵喔喔
浏览 78回答 1
1回答

鸿蒙传说

我可能误解了你的意思,但我想只使用普通的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.")
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python