當使用記錄器時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 回答

鴻蒙傳說
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
提交
取消