oop - Python: accessing attributes and methods of one class in another -
let's have 2 classes , b:
class a: # a's attributes , methods here class b: # b's attributes , methods here now can assess a's properties in object of b class follows:
a_obj = a() b_obj = b(a_obj) what need 2 way access. how access a's properties in b , b's properties in ?
you need create pointers either way:
class a(object): parent = none class b(object): def __init__(self, child): self.child = child child.parent = self now a can refer self.parent (provided not none), , b can refer self.child. if try make instance of a child of more 1 b, last 'parent' wins.
Comments
Post a Comment