How to get 'type' field descriptor from ctypes Structure or Union field

后端 未结 2 727
情书的邮戳
情书的邮戳 2021-01-05 16:17

I have a structure with different datatype fields. I would like to iterate through the structure fields, check the datatype, and set the field with an appropriate value.

2条回答
  •  自闭症患者
    2021-01-05 16:24

    Just use the _fields_ list:

    >>> for f,t in A._fields_:
    ...  a = getattr(A,f)
    ...  print a,a.offset,a.size,t
    ...
     0 4 
     4 1 
     5 1 
    

提交回复
热议问题