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"
0

1 Answer 1

5

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).

Sign up to request clarification or add additional context in comments.

2 Comments

'\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: you can just lstrip this character.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.