I have a class that has instances of other classes as its properties:
from ctypes import *
class C():
A = propA()
B = propB()
def __init__(self):
class c_struct(Structure):
_fields_ = [('_A', c_int), ('_B', c_int)]
self._c_struct = c_struct()
I need to somehow "connect" the propA
and propB
classes to the internal structure _c_struct
created in C
to eventually get the behavior like so:
c = C()
c.A.val = 12
c.B.val = 13
c._c_struct._A == c.A.val == 12
Where C.A
is able to manipulate C._c_struct._A
. I've attempted to do something like this:
from ctypes import *
class propParent():
def set_ref(self, ext_ref):
self._val = ext_ref
@property
def val(self):
return self._val
@val.setter
def val(self, val):
self._val = val
class propA(propParent):
# Further definitions here
pass
class propB(propParent):
# Further definitions here
pass
class C():
A = propA()
B = propB()
def __init__(self):
class c_struct(Structure):
_fields_ = [('_A', c_int), ('_B', c_int)]
self._c_struct = c_struct()
self.A.set_ref(self._c_struct._A)
self.B.set_ref(self._c_struct._B)
But it appears that self._c_struct._A
returns a Python integer object and not the reference to the _A
internal c_int object of the structure. How do I connect a property to a sub property of another property in the same class?