通过套接字连接接收数据字符串.当收到第一个动作变量将 = 'IDENTIFY' 的示例时,它起作用了.但是当收到第二个例子时,其中的 action variable will = 'MSG' 它不会比较.
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.
最奇怪的是,当我使用 Telnet 而不是我的套接字客户端时,两者都被成功比较.但是字符串是相同的......字符串是否有可能以不同的方式编码?我怎么知道?
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 = '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" 推荐答案无法重现您的问题.要调试它,打印或记录 data 和 action 的 repr():这可能会告诉你原因(可能是一些不可见的二进制字节已潜入 data,根据您获取它的方式 [[您没有向我们展示]] 并因此进入 action).
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).
更多推荐
相同的字符串在 Python 中返回 FALSE 并带有 '==',为什么?
发布评论