Using super : Super : Class PYTHON TUTORIALS


PYTHON TUTORIALS » Class » Super »

 

Using super


class A(object:
    def __init__(self:
        self.a = 1

    def multiply(self, v:
        return self.a * v

class B(object:
    def __init__(self:
        self.b = 2

    def save(self:
        print "Saving Object.."
        for a in vars(self:
            print "Saving " + a

class C(A,B:
    def __init__(self:
        A.__init__(self)
        B.__init__(self)

    def multiply_and_save(self, v:
        super(C,self).multiply(v)
        super(C,self).save()

c = C()
c.multiply_and_save(3)

class Save(object:
    def __init__(self:
        self.filename = "save.txt"

    def save(self:
        fH = open(self.filename, "w")
        for a in vars(self:
            fH.write)
            fH.write"=" )
            fH.writestr(self.__dict__[a]) )
            fH.write("n")
        fH.close()


class D(Save:
    def __init__(self:
        Save.__init__(self)
        self.name = "D"
        self.value = 3
        self.color = "blue"

    def __del__(self:
        super(D, self).save()

d = D()
del d



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Class
» Super