1
私はPythonのctypesをはじめて使用しています。私の意図は、Pythonのリストをctype共用体内にある配列に変換することです。しかし、これをやろうとするとTypeErrorが発生します。私はこのシナリオに適した例を見つけることができなかったので、以下のコードを貼り付けました。 コメントしてください。ctypes union内の配列へのアクセス
from ctypes import *
class state_struct(Structure):
_fields_ = [
("loc0", c_uint32 * 3),
("loc1", c_uint32),
("loc2", c_uint32 * 12),
("loc3", c_uint32 * 28),
("loc4", c_uint32 * 2),
]
class state_union(Union):
_fields_ = [("state_struct", state_struct),
("data", c_uint32 * 46),
]
def populate_union():
u = state_union()
l = [1,2,3]
for i in iter(l):
u.state_struct.loc0 = i
populate_union()
はTypeError:予想c_uint_Array_3インスタンス、int型