python unpack 跟 php unpack区别
python unpack 和 php unpack区别$body unpack(Lcmd/Lstatus/a*username, $body_string)cnt unpack
python unpack 和 php unpack区别
$body = unpack("Lcmd/Lstatus/a*username", $body_string);
cnt = unpack('LLs', body_string)
同样的
body_string php能解出来, python总是报错。
觉得 php Lcmd/Lstatus/a*username 与 python LLs 有区别 。 求解答? Python PHP
[解决办法]看文档嘛,格式s不大一样,一般前面要带个数字表示字串长度,没有的话默认为1等同c不是你要的吧...
offset = struct.calcsize('2L')
cmd, status = struct.unpack('2L', body_string[:offset])
username = body_string[offset:]
或者:
fmt = '2L%ds' % (len(body_string) - struct.calcsize('2L'))
cmd, status, username = struct.unpack(fmt, body_string)