refering to base classes

Bruno Desthuilliers onurb at xiludom.gro
Wed Aug 30 04:32:47 EDT 2006


glenn wrote:
> Bruno Desthuilliers wrote:
> 
(snip)
>>
>> Here you could use a class attribute to provide a default:
>>
>> class Creature(object):
>>   noise = ""
>>
>>   def voice(self):
>>     return "voice:" + self.noise
>>
>>
>> class Dog(Creature):
>>   noise="bark"
>>
>>   def voice(self):
>>     print "brace your self:"
>>     return Creature.voice(self)
>>     # can also use this instead, cf the Fine Manual
>>     return super(Dog, self).voice()
>>
(snip)

> so for your $.02 do you see this as being, umm, superior in anyway to
> creature.voice()?

I suppose "this" refers to the use of super() ? If so, I wouldn't say
it's "superior", but it can be helpful with complex inheritence scheme
(something that does'nt happen very frequently in Python), and more
specifically with multiple inheritance. You may want to read this for
more infos:

http://www.python.org/download/releases/2.2.3/descrintro/#mro

HTH
-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list