Chaz Ginger wrote:

> Chaz Ginger wrote:
> > glenn wrote:
> >> hi - Im quite new to python, wondering if anyone can help me understand
> >> something about inheritance here. In this trivial example, how could I
> >> modify the voice method of 'dog' to  call the base class 'creatures'
> >> voice method from with in it?
> >>
> >> class creature:
> >>     def __init__(self):
> >>         self.noise=""
> >>     def voice(self):
> >>         return "voice:" + self.noise
> >>
> >> class dog(creature):
> >>     def __init__(self):
> >>         self.noise="bark"
> >>
> >>     def voice(self):
> >>             print "brace your self:"
> >>
> >> thanks
> >> glenn
> >>
> > Try this:
> >
> > class dog(creature):
> >     .....
> >     def voice(self):
> >         print "brace your self:"
> >         creature.voice(self)
> >
> > This should do it.
> I did forget to mention that in 'dog"s' __init__ you had better call
> creature's __init__. You might make it look like this:
>
> def __init__(self):
>       self.noise = 'bark'
>       creature.__init__(self)
>
> There is another approach - using Superclass - but I will leave that
> exercise to the reader.
first tip worked - funny thing was I =thought= I done that, but clearly
not - so thanks was going mad.
Superclass?... ok will look into this
thanks for reply(s)
Glenn

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to