0
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的:「模塊」對象有沒有屬性「包」
AttributeError: 'module' object has no attribute 'pack'
我使用python 2.7.5,我已經檢查模塊列表和「結構」在那裏。
您的代碼適用於我。 Daniel Roseman的回答可能是準確的。 –
我有同樣的錯誤,並沒有一個名爲struct.py的文件(做了'find。-name struct.py') – 2013-09-24 14:53:42