Python: Can we convert a ctypes structure to a dictionary?

后端 未结 3 1304
没有蜡笔的小新
没有蜡笔的小新 2021-02-20 08:02

I have a ctypes structure.

class S1 (ctypes.Structure):
    _fields_ = [
    (\'A\',     ctypes.c_uint16 * 10),
    (\'B\',     ctypes.c_uint32),
    (\'C\',            


        
3条回答
  •  不要未来只要你来
    2021-02-20 08:36

    How about something like:

    class S1(ctypes.Structure):
        _fields_ = [ ... ]
    
        def getdict(self):
            dict((f, getattr(self, f)) for f, _ in self._fields_)
    

提交回复
热议问题