[Python] ctype 的型態小記
ctype的形式可參考 官網 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 None 上圖引用自官網 另外標示,如果使用uint_32t等等型態,可利用c_uint32 如果是char的陣列,則可以直接利用char*字串長度 而結構(Struct)的建構則為: from ctype import * class Structex(Structure): _fields_ = [ ('name', c_char *10), #= c , char[10] ('age', c_int) #= c , int ] 利用_fields_和上表可以