davef21370 wrote:In this code is there any way for the 'thisInner' instance to alter 'someData' in 'myOuter'?
Code: Select all
class Inner:
def changeData(self, newData):
how to change someData data to newData ??
class Outer:
def __init__(self):
someData = 1234
thisInner = Inner()
myOuter = Outer()
myOuter.thisInner.changeData(5678)
The final code will have a number of "outers" each containing a number of
different "inners".
Dave.
As you have it Inner knows nothing about Outer. You could have Inner take an extra parameter when initializing that contains the parent object and have Outer pass itself as that.
Something along the lines of
Code: Select all
class Inner:
def __init__(self, parent):
self.outer = parent
def changeData(self, newData):
self.outer.someData = newData
class Outer:
def __init__(self):
self.someData = 1234
self.thisInner = Inner(self)
myOuter = Outer()
myOuter.thisInner.changeData(5678)