The error explains exactly this problem, but in a slightly confusing way:
The correct way to initialize such an array is as follows:
structs = [A(1, 2), A(1, 2)]
array = (A * 2)(*structs)
Or, if you can define them all during the array constructor as follows:
array = (A * 2)(A(1, 2), A(1, 2))
, ? A A * 2, A. A , . A, A.
:
from ctypes import *
class A(Structure):
_fields_ = [('a', c_int), ('b', c_int)]
a_array_factory = A * 2
struct_1 = A(1, 2)
struct_2 = A(2, 3)
array = a_array_factory(struct_1, struct_2)
EDIT:
Python, , . Python C :
ctypes type C type Python type
c_bool _Bool bool (1)
c_char char 1-character string
c_wchar wchar_t 1-character unicode string
c_byte char int/long
c_ubyte unsigned char int/long
c_short short int/long
c_ushort unsigned short int/long
c_int int int/long
c_uint unsigned int int/long
c_long long int/long
c_ulong unsigned long int/long
c_longlong __int64 or long long int/long
c_ulonglong unsigned __int64 or unsigned long long int/long
c_float float float
c_double double float
c_longdouble long double float
c_char_p char * (NUL terminated) string or None
c_wchar_p wchar_t * (NUL terminated) unicode or None
c_void_p void * int/long or Nonee or None