views:

244

answers:

1

The data string is receive through a socket connexion. When receiving the first example where action variable would = 'IDENTIFY', it works. But when receiving the second example where action variable would = 'MSG' it does not compare.

And the most bizarre thing, when I use Telnet instead of my socket client both are being compare successfully. But the string are the same... Is there a possibility that the string are not encode in the same way? How can I know?

data example:

data = 'IDENTIFY 54143'
or
data = 'MSG allo'

action = data.partition(' ')[0]
if action == "MSG":
    self.sendMessage(data)
elif action == "IDENTIFY":  
    self.sendIdentify(data)
else:
    print "false"
+1  A: 

Can't reproduce your problem. To debug it, print or log the repr() of data and action: this will likely show you the cause (probably some non-visible binary byte has snuck into data, based on how you obtained it [[which you don't show us]] and hence into action).

Alex Martelli
'\x00MSG Allo' that's what I get. I will try to find how to escape it. Tks a lot!Tks since i'm new to python I did not know repr().
plehoux
@plehoux: you can just `lstrip` this character.
SilentGhost