当使用记录器时Import logginglogging.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}")工作正常我想知道使用记录器执行此操作的最巧妙方法是什么,有多行,所以我想按每个项目的行拆分它们
1 回答
![?](http://img1.sycdn.imooc.com/54584ef20001deba02200220-100-100.jpg)
鸿蒙传说
TA贡献1865条经验 获得超7个赞
我可能误解了你的意思,但我想只使用普通的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.")
添加回答
举报
0/150
提交
取消