python的struct模块可以让我们很方便的操作二进制数据,但是我们必须注意的是:我们在使用struct进行二进制操作的时候会发现,操作系统和硬件将影响程序是否正常运行。

Format = 'lllllfll'
 f = open('test.dat','rb')
 data = f.read(32)
 s=[]
 s.append(struct.unpack(Format,data))

32位下正常,64位下报:“struct.error: unpack requires a string argument of length 64”
同样是64位的操作系统,Windows和UNIX行为可能不太一样。UNIX上的long可能是64位,Windows可能就是32位。

 

python语言的整形相当于C语言中的long型,在32位机器上位宽为32位,在64位系统上,整型的位宽为64位。

相关文章:

  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
  • 2021-10-19
  • 2022-01-18
  • 2022-12-23
  • 2021-12-25
猜你喜欢
  • 2021-05-26
  • 2022-12-23
  • 2021-09-07
  • 2022-12-23
  • 2019-01-09
  • 2021-12-25
  • 2021-06-29
相关资源
相似解决方案