【发布时间】:2014-06-12 13:20:24
【问题描述】:
当我用 ctypes 读取二进制数据时,它不能正常工作。
二进制数据
03 00 00 00 49 7B 00 00 00 00 00 00
python 代码
from ctypes import *
class DataStructure(Structure):
_fields_ = [
("long1", c_ulong),
#("long2", c_ulong),
("longlong", c_ulonglong)
]
binaryfile = "./ULongLong"
f = open(binaryfile, "rb")
mystruct = DataStructure()
f.readinto(mystruct)
if __name__ == "__main__":
print mystruct.long1
#print mystruct.long2
print mystruct.longlong
结果
3
0
但是当我改为读取二进制数据并取消注释 python 代码时,它工作正常。
03 00 00 00 03 00 00 00 49 7B 00 00 00 00 00 00
结果
3
3
31561
这似乎是一个错误。有人可以帮我解决这个问题吗? 任何建议都将不胜感激。
环境: 视窗 7 x64 Python 2.7 x32 ctypes 1.1.0
【问题讨论】: