def __init__(self, **kwargs):
"""
Ctypes.Structure with integrated default values.
https://stackoverflow.com/questions/7946519/default-values-in-a-ctypes-structure/25892189#25892189
:param kwargs: values different to defaults
:type kwargs: dict
"""
# sanity checks
defaults = type(self)._defaults_
assert type(defaults) is types.DictionaryType
# use defaults, but override with keyword arguments, if any
values = defaults.copy()
for (key, val) in kwargs.items():
values[key] = val
# appropriately initialize ctypes.Structure
#super().__init__(**values) # Python 3 syntax
return Structure.__init__(self, **values) # Python 2 syntax
# http://stackoverflow.com/questions/1825715/how-to-pack-and-unpack-using-ctypes-structure-str/1827666#1827666
# https://wiki.python.org/moin/ctypes
评论列表
文章目录