[Tutor] How to load a dict into a dict subclass?

Alan Gauld alan.gauld at btinternet.com
Tue Oct 27 18:49:33 CET 2009


"Wayne" <srilyk at gmail.com> wrote 

> My favorite example (and the easiest to understand) deals with shapes:
> 
> class Shape:
>     def __init__(self):
>        self.sides = 0
>        self.area = 0
> 
> class Triangle(Shape):
>     Shape.__init__(self)
>     def __init__(self, base=0, height=0):
>         self.sides = 3
>         self.area = base/2*height

Shouldn't the Shape.__init__() call be inside the constructor?
Or is there some deep subtle thing going on here that I'm missing?

Also how does subclassing Shape add any value here since 
we just create local instance vars for sides and area anyway
if they don't already exist?

Or is this a case of simplifying an example one step too far?

Confusedly,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list