當(dāng)使用記錄器時(shí)Import logginglogging.info( f"This is a \nid: {id}", \ f"\nclaim number: {claim_number}")導(dǎo)致錯(cuò)誤TypeError: not all arguments converted during string formatting ,而print( f"This is a \nid: {id}", \ f"\nclaim number: {claim_number}")工作正常我想知道使用記錄器執(zhí)行此操作的最巧妙方法是什么,有多行,所以我想按每個(gè)項(xiàng)目的行拆分它們
1 回答

鴻蒙傳說(shuō)
TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊
我可能誤解了你的意思,但我想只使用普通的f 字符串就可以解決問(wèn)題,而不是使用“\”來(lái)分割日志記錄。
試試這個(gè):
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.")
添加回答
舉報(bào)
0/150
提交
取消