There's something about indirectly linking to an attribute that apparently I don't understand. If I have a class, and I create a nested class which has a variable that points to the parent/controller class variable, I thought it should change when the controllers variable changes.
Example:
class A():
def __init__(self):
self.A_value = 10
print("A_value in A after init: " + str(self.A_value))
self.B = self.B(self)
print("")
print("A_value in A after B init: " + str(self.A_value))
print("B_value in B after B init: " + str(self.B.B_value))
class B():
def __init__(self, controller):
self.B_value = controller.A_value
print("B_value in B after init: " + str(self.B_value))
controller.A_value = 1
print("B_value in B after change: " + str(self.B_value))
A()
which results in
A_value in A after init: 10
B_value in B after init: 10
B_value in B after change: 10
A_value in A after B init: 1
B_value in B after B init: 10
What I expect to happen is B_value to be 1 at the end too, since it points to A_value. Why doesn't B_value change? Honestly, I don't understand why half my code works if this doesn't. And I'm having a hard time coming up with a way to search for the correct, I know that this is definitely answered in some way somewhere.
(tested in Python 2.7 and 3.7)