【发布时间】:2021-04-07 20:02:45
【问题描述】:
我有一个python函数如下,当启用pylint进行代码扫描时,它会抛出一个惰性格式化错误。
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}))
【问题讨论】:
-
最佳实践是使用 f-string。换成
logging.exception(f"ModifyResponseError: {e}") -
stackoverflow-lint 警告:问题没有指出哪一行失败。问题不会发布错误消息。
-
@K.Mat 你对 f-strings 有同样的问题。请参阅 tdelaney 的答案。
标签: python logging error-handling formatting pylint