I have created two class A and B (use @property
to get and set their attribute). class B has a member whose type is class A. How to set the attribute of b.a.x
?
class A:
class A(object):
def __init__(self, x=0, y=0):
self._x = x
self._y = y
@property
def x(self):
return self._x
@x.setter
def x(self, value):
self._x = value
@property
def y(self):
return self._y
@y.setter
def y(self, value):
self._y = value
class B:
class B(object):
def __init__(self):
self._a = A()
@property
def a(self):
return self._a
@a.setter
def a(self, value):
if isinstance(value, A):
self._a = deepcopy(value)
elif isinstance(value, tuple):
self._a = A(value[0], value[1])
elif isinstance(value, int):
# ?
pass
b = B()
b.a.x = 1 # How to implementate this ?
Am I wrong with the using of @property
?