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

Wayne srilyk at gmail.com
Tue Oct 27 20:36:55 CET 2009

On Tue, Oct 27, 2009 at 12:49 PM, Alan Gauld <alan.gauld at btinternet.com>wrote:

> "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,
Probably, to all of the above it's applicable to - I've (1) been coding in
C++ all morning, (2) was kinda in a hurry, and (3) haven't seen the *actual*
example I saw in my CS class for at least a year - it was just the concept
of using subclasses that stayed with me.

There's probably a wealth of better information out there for the curious
individual, and I probably should have just grabbed a link.

I'm presuming if you were really doing something like that, the Shape class
would take more arguments for instantiation, as well as do some other more
useful things.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091027/3fac018c/attachment.htm>

More information about the Tutor mailing list