refering to base classes

glenn glenn at tangelosoftware.net
Wed Aug 30 06:49:29 EDT 2006


thanks - interesting essay/article -  a lot in their I've never really
considered - though its only recently ive started playing with multiple
inheritance in any context - thanks for that
Bruno Desthuilliers wrote:
> 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