class function access other class function python code example
Example 1: call a function from another class python
class A:
def method1(arg1, arg2):
class B:
A.method1(1,2)
Example 2: access class variable from another class python
class ClassA(object):
def __init__(self):
self.var1 = 1
self.var2 = 2
def methodA(self):
self.var1 = self.var1 + self.var2
return self.var1
class ClassB(ClassA):
def __init__(self, class_a):
self.var1 = class_a.var1
self.var2 = class_a.var2
object1 = ClassA()
sum = object1.methodA()
object2 = ClassB(object1)
print sum