Я написал следующий код, пытаясь выяснить, как создавать экземпляры подклассов в основном классе ... Я придумал что-то, что не подходит ... по крайней мере для меня
Что-то не так с этим типом инстансинга? Есть ли лучший способ для вызова подклассов?
class Family():
def __init__(self):
self.Father = self.Father(self)
self.Mother = self.Mother(self)
class Father():
def __init__(self, instance = ''):
self = instance if instance != '' else self
print self
def method(self):
print "Father Method"
def fatherMethod(self):
print "Father Method"
class Mother():
def __init__(self, instance = ''):
self = instance if instance != '' else self
print self
def method(self):
print "Mother Method"
def motherMethod(self):
print "Mother Method"
if __name__ == "__main__":
Family = Family()
Family.Father.method()
Family.Mother.method()