I have following code that defines outer and inner classes. I would like to get the instances of the inner class created under one specific instance of the outer class.
class schema():
def __init__(self,name):
self.name=name
class node():
nodes=[]
def __init__(self,name):
self.name=name
self.nodes.append(self)
def __call__(self):
return(self.name)
When I create two instances of the class schema with two different instances of the inner class node I would like to get only the instances of the inner class associated to one of the outer instance.
a=schema('A')
a1=a.node('A1')
a2=a.node('A2')
b=schema('B')
b1=b.node('B1')
b2=b.node('B2')
print({n() for n in a.node.nodes})
I get:
{'B1', 'A1', 'B2', 'A2'}
But I would like to get:
{'A1', 'A2'}
Thank you.