PythoncTypes:从指针变量获取指针类型
我有一个包含基本字段(int,uint8,…)和指针的结构。 这些指针通常指向不同结构类型的数组,以保持深度嵌套的结构。 例如,在C中:PythoncTypes:从指针变量获取指针类型,python,pointers,types,structure,ctypes,Python,Pointers,Types,Structure,Ctypes,我有一个包含基本字段(int,uint8,…)和指针的结构。 这些指针通常指向不同结构类型的数组,以保持深度嵌套的结构。 例如,在C中: struct A { int field1; int field2; struct B *fields3; unsigned int countofb; } struct B { int anotherfield1; int anotherfield2; } 在使用ctypes的python中,我创建了结构a和B的包装器。 迭代结构A的\u
struct A
{
int field1;
int field2;
struct B *fields3;
unsigned int countofb;
}
struct B
{
int anotherfield1;
int anotherfield2;
}
在使用ctypes的python中,我创建了结构a和B的包装器。
迭代结构A的\u字段
,我到达第三个字段field3
,得到类型为LP\u struct\u B
的ctype变量
问题是,是否有一种方法,一个函数,一种将指针转换为指针类型的ctypes方法
我需要像这样的东西
a=A()
st=pointedtype(a.field3) # or also st = pointedtype2(LP_struct_B)
#desired output: st = struct_B
谢谢好的。
我已经根据经验找到了答案。
只需使用变量或指针类型的属性\u type\
a=A()
print a.fields3._type_ # struct_B
tipo=type(a.fields3) # tipo=LP_struct_B
print tipo._type_ # struct_B