If none of the above python -




i have series of checks need run on sensor data, checks independent can't formatted elifs or elses, if checks fail, need print user. if none of checks fail want tell user sensor okay

(i iterator going on sensors in array)

if worst_stdev[i] > 5:     print("sensor bad, stdev value: {}".format(worst_stdev[i])) if worst_invalid[i] > 2:     print("sensor bad, invalid value: {}".format(worst_invalid[i])) if worst_err[i] > 1:     print("sensor bad, error value: {}".format(worst_bit_err[i])) if not (worst_stdev[i] > 5 or worst_invalid[i] > 2 or worst_err[i] > 1):     print("sensor ok") 

the last if statement bugs me most, feels redundant (and possibly slower?) check again things i've checked. there way make more elegant?

i keep flag variable keeps track of errors. example:

was_error = false if worst_stdev[i] > 5:     print("sensor bad, stdev value: {}".format(worst_stdev[i]))     was_error = true if worst_invalid[i] > 2:     print("sensor bad, invalid value: {}".format(worst_invalid[i]))     was_error = true if worst_err[i] > 1:     print("sensor bad, error value: {}".format(worst_bit_err[i]))     was_error = true if not was_error:     print("sensor ok") 

alternatively have several different error variables can tell error occurred. if don't care error thrown, want know how many of them there were, can increment error variable each time. has upshot of still working syntax if not was_error:





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -