import struct
f = open('file.bin', 'wb')
value = 1.23456
data = struct.pack("f", value)
f.write(data)
f.close()
f = open('file.bin', 'rb')
print struct.unpack('f',f.read(4))
f.close()
我尝试执行上面的代码,它给了我错误:
AttributeError: 'module' object has no attribute 'pack'
我使用的是 python 2.7.5,我已经检查了模块列表,其中有“struct”。
请您参考如下方法:
您的本地目录中有一个名为 struct.py 的文件,它隐藏了标准库版本。
