import ctypes
import struct
class _sPOS(ctypes.Structure):
_fileds_ = (
("POSX", ctypes.c_double),
("POSY", ctypes.c_double)
)
sPOS = _sPOS()
class _sPOSE(ctypes.Structure):
_fileds_ = (
("sPOSX", sPOS),
("sPOSY", sPOS),
("sDirection", ctypes.c_double)
)
with open('/Users/machcross/Desktop/MasterDB_03M17D15H34m54s.dat','wb') as f:
sPOSE = _sPOSE()
sPOSE.sPOSX = 0.1
sPOSE.sPOSY = 0.2
sPOSE.sDirection = 0.01
size = ctypes.sizeof(sPOSE)
print(size)
如何获得sPOS的大小? len(sPOS)不起作用.. ctypes.sizeof(sPOS)为零..
我想知道使用bytearray(sPOS)的方法。 ex)buf =((char *)& _sPOS,sizeof(sPOS))