Python 在日志函数pylint错误消息中使用惰性%格式
我有一个python函数,如下所示,当启用pylint进行代码扫描时,它会抛出一个延迟格式错误Python 在日志函数pylint错误消息中使用惰性%格式,python,logging,error-handling,formatting,pylint,Python,Logging,Error Handling,Formatting,Pylint,我有一个python函数,如下所示,当启用pylint进行代码扫描时,它会抛出一个延迟格式错误 def modify_response(data): try: response = {} response["User_ID"] = data[0]["User_ID"]["S"] response["Triggered_Timestamp"] = data[0][
def modify_response(data):
try:
response = {}
response["User_ID"] = data[0]["User_ID"]["S"]
response["Triggered_Timestamp"] = data[0]["Triggered_Timestamp"]["S"]
return response
except Exception as e:
logging.exception("ModifyResponseError: {}".format(e))
raise ModifyResponseError(json.dumps({"httpStatus": 501,"message": internal_error_message}))
假设这条线是
logging.exception("ModifyResponseError: {}".format(e))
警告是
W1202: Use lazy % formatting in logging functions (logging-format-interpolation)
应该向日志函数传递格式字符串和参数,而不是已经格式化的字符串。否则,格式化操作本身可能会在日志记录发生之前引发异常。这些都是老派的。派林也会因为同样的原因抱怨f字符串
林特会很高兴的
logging.exception("ModifyResponseError: %s", e)
有关详细信息,请参阅。假设该行为
logging.exception("ModifyResponseError: {}".format(e))
警告是
W1202: Use lazy % formatting in logging functions (logging-format-interpolation)
应该向日志函数传递格式字符串和参数,而不是已经格式化的字符串。否则,格式化操作本身可能会在日志记录发生之前引发异常。这些都是老派的。派林也会因为同样的原因抱怨f字符串
林特会很高兴的
logging.exception("ModifyResponseError: %s", e)
有关详细信息,请参阅。最佳做法是使用f字符串。更改为
logging.exception(f“ModifyResponseError:{e}”)
stackoverflow lint警告:问题没有注意到哪一行失败。问题不会发布错误消息。最佳做法是使用f字符串。更改为logging.exception(f“ModifyResponseError:{e}”)
stackoverflow lint警告:问题没有注意到哪一行失败。问题不会发布错误消息。