需要你的帮助。 “matcherror”是一个列表,包含需要与“errormsg”匹配的错误代码列表。我想使用“errormsg”中提到的完整错误消息匹配“代理未经授权预付”,并忽略其他参数(即忽略总费用= 10812.00000,总付款= 10308“。事实上,无论我在”matcherror“中提到什么,都应该与”errormsg“匹配,并忽略句子的其余部分。
matcherror = ["['Connection Refused']","['Link Down']","['Agent is not authorized to under pay on a booking.']"]
errormsg = "Agent is not authorized to under pay on a booking. Total Cost = 10812.00000, Total Payment = 10308"
我正在尝试实现类似的目标:
matcherror = ["['Connection Refused']","['Link Down']","['Agent is not authorized to under pay on a booking.']"]
errormsg = "Agent is not authorized to under pay on a booking. Total Cost = 10812.00000, Total Payment = 10308"
evaluate = matcherror in errormsg
if evaluate == True:
send_email(showfailure)
else:
print "No failure for this hour"
答案 0 :(得分:1)
您需要更改评估。您在list
中搜索string
。而是循环遍历list
并在string
中查找其每个元素。
import re
matcherror = ["['Connection Refused']","['Link Down']","['Agent is not authorized to under pay on a booking.']"]
errormsg = "Agent is not authorized to under pay on a booking. Total Cost = 10812.00000, Total Payment = 10308"
evaluate=False
for i in matcherror:
if re.sub(r"^\['|'\]$","",i) in errormsg:
evaluate=True
if evaluate == True:
print "Fail"
else:
print "No failure for this hour"