Reputation: 107
I have a python script parse an incoming payload at set a variable named "confidence" and "id" then it will evaluate if the id is equal to sam@sam and that confidence is greater than or equal to 70. Now the id is equal sam@sam but confidence is not, it will still trigger! whats wrong with my code!!?
p = eg.event.payload[2]
p = p.split(',')
id = p[0].strip()
confidence = p[1].strip()
print confidence
url = p[2].strip()
if confidence >= 70 and id == "sam@sam":
eg.TriggerEvent("FaceRec", "Unlock Door" )
else:
eg.plugins.GoogleVoice.SendSMS(u'407#####', url)
Upvotes: 2
Views: 242
Reputation: 10727
Ok, let's take a closer look at your code. Now, p is a string. So when you split it, the results(id and confidence) are strings. That's your problem. Since confidence is still a string when you compare the values, you are comparing a string and an int. Do this:
confidence = int(p[1].strip())
This converts the string to an int first, so, confidence will be an int. The comparison will then work properly.
Upvotes: 4
Reputation: 10003
The problem is that "confidence" is a string and you are comparing it to a number. The result of comparing string to a number is consistent, but not necessarily the one you want.
Fix:
confidence = int(p[1].strip())
Upvotes: 12