I am a bit confused on how object values persist in python.
Let say I have an class object a that has a specific set of attributes attached to it. Multiple classes B, C have their own references to class a when each of them are created. Only class C can modify stuff in class a. When it is modified, does class B pick them up? From creating my own example they seem to do so.
My question is are there any instances where I should be aware of when changes to wont be picked up? When does python create an copy of class a? More specifically, what will create a copy of it that wont affect the original a.
class A:
def __init__(self):
self.x = 1
def changeX(self,num):
self.x = num
class B:
def __init__(self,classA):
self.x = classA
class C:
def __init__(self,classA):
self.x = classA
def ChangeA(self,num):
self.x.changeX(num)
c_a = A()
c_b = B(c_a)
c_c = C(c_a)
c_c.ChangeA(2)
# All returns 2
c_a.x
c_b.x.x
c_c.x.x