Python的struct使用注意
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位。
相关推荐
huavhuahua 2020-11-20
weiiron 2020-11-16
cakecc00 2020-11-15
千锋 2020-11-15
JakobHu 2020-11-14
guangcheng 2020-11-13
xirongxudlut 2020-11-10
solarLan 2020-11-09
pythonxuexi 2020-11-08
文山羊 2020-11-07
susmote 2020-11-07
wuShiJingZuo 2020-11-05
Pythonjeff远 2020-11-06
jacktangj 2020-11-04
lousir 2020-11-04
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17