refering to base classes

Chaz Ginger cginboston at hotmail.com
Tue Aug 29 10:53:10 EDT 2006


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.



More information about the Python-list mailing list