mercredi 8 novembre 2017

Evaluating if variable in list python

I am using a RFID reader to scan multiple RFID tags. The readings are placed into a list. I am trying to check if a tag is in the reading. Using the 'if in' method is not working for me.

tag1 = 'E2004005730702602190360B'
tag2 = 'E20040057307026421903619'

while True:
    a = reader.read()
    print (a)
    if tag1 in a:
            print('tag1')
            time.sleep(0.2)
            break
    if tag2 in a:
            print('tag2')
            time.sleep(0.2)
            break
    time.sleep(0.2)

My terminal is output is: Terminal output

So the if conditions is not executed when tag1 or tag2 are in a.

I can't seem to make it enter the if condition. Any advice?

Aucun commentaire:

Enregistrer un commentaire