Is it possible to modify the fields definition of the ctypes.Structure after it's been imported?
Something like:
from ctypes import *
class A_STRUCT(Structure):
_fields_ = [("one",c_int)]
A_STRUCT._fields_.append(("two",c_int))
x = A_STRUCT()
print x.one
print x.two
Not surprisingly this fails with:
0
Traceback (most recent call last):
File "structEnumTest.py", line 10, in <module>
print x.two
AttributeError: 'A_STRUCT' object has no attribute 'two'
EDITS
My use case is that I have two version of A_STRUCT. Version 2 is the same with additional fields appended to the end of version one. I was hoping to avoid having something like this. I do not know which version of the struct is needed until run-time.
class A_STRUCT_V1(Structure):
_fields_ = [("one",c_int)]
class A_STRUCT_V2(Structure):
_fields_ = [("one",c_int),("two",c_int)]