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

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -