Problems with python 2.4 and 2.4.4 in struct.unpack and win/lin

戏子无情 提交于 2019-12-11 02:58:39

问题


i'm coding on a Linux debian machine with python 2.4.

My neighbour with Windows XP and python 2.4.4

He can run this code:

w1, w2, w3 = unpack("LLL", pack("LLHH", localtime, ipddr, counter, aid))

But when i try this code i become this error:

w1, w2, w3 = unpack("LLL", pack("LLHH", localtime, ipddr, counter, aid))
struct.error: unpack str size does not match format

Can it be the Version of python or maybe the system?


回答1:


Use the I format code instead of L.

On your Linux machine, L isn't twice as long as H, it's four times as long -- 8 bytes (64 bits) instead of 4 bytes (32 bits).

I should be 4 bytes (32 bits) on both.

Edit: Make sure to read eryksun's comment.



来源:https://stackoverflow.com/questions/7583687/problems-with-python-2-4-and-2-4-4-in-struct-unpack-and-win-lin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!