post init call

Prashant animator333 at gmail.com
Mon Jun 18 03:10:53 EDT 2012


class Shape(object):
    def __init__(self, shapename):
        self.shapename = shapename
        
        
    def update(self):
        print "update"

class ColoredShape(Shape):
    def __init__(self, color):
        Shape.__init__(self, color)
        self.color = color
        print 1
        print 2
        print 3
        self.update()

User can sub-class 'Shape' and create custom shapes. How ever user must call 'self.update()' as the last argument when ever he is sub-classing 'Shape'.
I would like to know if it's possible to call 'self.update()' automatically after the __init__ of sub-class is done?

Cheers



More information about the Python-list mailing list