I have 2 classes A and B. How can class B access parameters that are in class A?
It cannot directly access class members unless it has access to the object. Otherwise you might need to define static variables.
1 Like
How to give access to its object ? Please could you type a sample code?
Sure, here is a small example:
class A(object):
def __init__(self, B):
self.B = B
print(self.B.internal_attribute)
class B(object):
def __init__(self):
self.internal_attribute = 2.8
b = B()
a = A(b)
# 2.8
1 Like