1

Need you help. "matcherror" is a list and contains list of error codes which it needs to match with "errormsg". I want to match "Agent is not authorized to under pay on a booking" with the full error message mentioned in the "errormsg" and ignore the other parameters (i.e ignore Total Cost = 10812.00000, Total Payment = 10308". In-fact whatever i mention in the "matcherror" should match with the "errormsg" and ignore rest of the sentence.

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"

Bacially i am trying to achieve something like:

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"
fear_matrix
  • 4,377
  • 9
  • 40
  • 62

1 Answers1

1

You need to change your evaluate.You searching for a list in string.Instead loop over list and find each of its element in 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"
vks
  • 63,206
  • 9
  • 78
  • 110
  • @fear_matrix http://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean – vks Oct 29 '15 at 08:45