隨着未來代碼:我不明白struct.unpack
shmem = mmap.mmap(0, 20, "MumbleLink", mmap.ACCESS_READ)
print("size: "+str(struct.calcsize("IL3f3f3f512s3f")))
print(struct.unpack("IL3f3f3f512s3f", shmem))
我得到這樣的輸出:
size: 568
Traceback (most recent call last):
File "C:\Users\Saelyth\Desktop\test.py", line 8, in <module>
print(struct.unpack("IL3f3f3f512s3f", shmem))
struct.error: unpack requires a bytes object of length 568
爲什麼它告訴我,它需要的長度,如果568的對象calcsize說它已經是568了?
此外,值得一提的是我一直在使用Google(和檢查This)對於什麼是IL3f3f3f512s3f或答案你怎麼能創建自己的字符串讀取的存儲器,例如1024,而不是568,而是使遠遠沒有運氣。關於這部分結構工程如何幫助的詳細答案,或者指出我如何理解如何計算我需要用來解壓縮shmem的字符串的正確方向。
這個和This問題有關。
什麼版本的Python? Py2將mmap作爲字符串處理,Py3作爲bytearrays –