python error get object value
I'm a bit new in programming with python, but I have do this code:
dimValue = 0
........
elif event[0] == "control" and body["location"] == location and body["action"] == "on":
auxValue = int(body["dim"])
print("AuxValue = " + str(auxValue))
if auxValue > dimValue:
print("entrou")
dimControl=auxValue-dimValue
print("DimControl 开发者_StackOverflow中文版= " + str(dimControl))
dimValue = auxValue
os.system("heyu bright A1 "+ str(dimControl))
elif dimValue > auxValue:
print("saiu")
dimControl=dimValue-auxValue
dimValue = auxValue
os.system("heyu dim A1 "+ str(dimControl))
With this code, if int(body["dim"]) is 5, just show the first print, and don't enter in the if else statement. If I comment this line "dimValue = auxValue", it enters in the if else, and do everything well. But I need to put this line. What I'm doing wrong?
Thanks.
Hugo Silva
It sounds like neither the if
block nor the elif
block are being entered. This probably occurs when auxValue equals dimValue; then neither of the criteria evaluate to true. You could change > to >= or change < to <=, depending on which block you want to run when they are equal.
精彩评论