Alright, let's start with the code, because it's pretty explicit :
class c_1:
def __init__(self):
self.a = 5
class c_2:
def __init__(self,other_obj):
self.other = other_obj
self.b = self.other.a
And the output:
obj_1 = c_1()
obj_2 = c_2(obj_1)
print(obj_2.b)
# Output is 5
obj_1.a = 8
print(obj_2.b)
# Output is still 5
This is the problem. I know the second call of obj_2.b should return 5, but I want it to return 8.
I think that what I actually want, is for the value of obj_1.a to be passed by reference for obj_2.b (this example is pretty simple, but in my actual code, there are more attributes from obj_1 that obj_2 uses.)
Is there a way, without calling another method, to automatically update obj_2.b when the value of obj_1.a gets changed ? Thank you.