structure - Python ctypes.BigEndianStructure can't store a value -
i in trouble ctypes.bigendianstructure. can't value set 1 fields. code this.
import ctypes class mystructure(ctypes.bigendianstructure): _pack_ = 1 _fields_ = [ ('fx', ctypes.c_uint, 7), ('fy', ctypes.c_ubyte, 1) ] x = mystructure()
it prints 0 excepted:
print x.fy # prints 0
then set value still prints 0:
x.fy = 1 print x.fy # still prints 0
i don't know why doing doesn't work , strange behavior. think alternative code works.
import ctypes class mystructure(ctypes.bigendianstructure): _pack_ = 1 def __init__(self): self.fx=ctypes.c_uint(7) self.fy = ctypes.c_ubyte(1) x = mystructure() x.fy = 7 print x.fy # prints 7
or without constructor::
import ctypes class mystructure(ctypes.bigendianstructure): _pack_ = 1 fx = ctypes.c_uint(7) fy = ctypes.c_ubyte(1) x = mystructure() x.fy = 7 print x.fy # prints 7
i have never used fields attribute can't speak odd behavior.
Comments
Post a Comment