Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Comment

PREVIOUS NEXT
Code Example
Python :: plotly color specific color 
Python :: pandas find all rows not null 
Python :: Get the square root of a number in Python 
Python :: list in list python 
Python :: django convert object to dict 
Python :: kivy dropdown list 
Python :: python slit 
Python :: how to take two space separated int in python 
Python :: multiple arguments with multiprocessing python 
Python :: django cleanup settings 
Python :: Flask command db migrate 
Python :: turn columns into one column as list python 
Python :: Python Date object to represent a date 
Python :: how to capitalize first letter in python in list using list comprehension 
Python :: python code execution time 
Python :: Could not find a version that satisfies the requirement ckeditor 
Python :: hover show all Y values in Bokeh 
Python :: delete outliers in pandas 
Python :: python swarm plot seaborn 
Python :: python check if array 
Python :: how to change values of dictionary in python 
Python :: serialization in django 
Python :: django-mathfilters 
Python :: how to rename files python 
Python :: Reverse an string Using Stack in Python 
Python :: how to return number in binary python 
Python :: how to add array in python 
Python :: python all permutations of a string 
Python :: python pandas return column name of a specific column 
Python :: how to go up levels in path python 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =