Python: How To Share Data Between Instances Of Different Classes?
Class BigClassA: def __init__(self): self.a = 3 def foo(self): self.b = self.foo1() self.c = self.foo2() self.d
Solution 1:
You are correct, in your case inheritance does not make sense. But, how about explicitly passing the objects during the instantiation. This would make a lot of sense.
Something like:
Class BigClassA:def__init__(self):
..
Class BigClassB:def__init__(self, objA):
self.b = objA.b
self.c = objA.c
self.d = objA.d
Class BigClassC:def__init__(self, objA, objB):
self.b = objA.b # need value of b from BigClassAself.f = objB.f # need value of f from BigClassB
While instantiating, do:
objA = BigClassA()
..
objB = BigClassB(objA)
..
objC = BigClassC(objA, objB)
Post a Comment for "Python: How To Share Data Between Instances Of Different Classes?"