samedi 3 octobre 2015

Python - True part of if condition always executes

No matter what's the value of what, the true part of if condition is always executed.

what = ""
def sendPacket(where, what):
        print("sendPacket()> i/p what :" + what)
        if what:
            zb.send('tx',dest_addr_long = where,dest_addr = UNKNOWN,data = what)
            print('sendPacket()> Data: '+ what) 
            print('sendPacket()> Data sent to: '+ where )
        else:
            print('sendPacket()> data not sent')

I want the true part to be executed only when what is not equal to null or empty. Any help would be appreciated.

Aucun commentaire:

Enregistrer un commentaire