refering to base classes
Steve Holden
steve at holdenweb.com
Wed Aug 30 02:15:46 EDT 2006
glenn wrote:
> Hi Roberto
>
>>If you want dog.voice() to just print "voice: bark", you just have to omit
>>the voice method for the dog class: it will be inherited from creature.
>>
>
> I would have thought this would be correct, but in this case, plus in
> others im playin with, I get this issue:
> -----------------------
> given animal.py is:
> class creature:
> def __init__(self):
> self.noise=""
> def voice(self):
> return "voice:" + self.noise
>
> class dog(creature):
> def __init__(self):
> self.noise="bark"
>
> then I get this outcome...
>
>>>>import animal
>>>>beagle=animal.dog
[...]
Shouldn't that be
beagle = animal.dog()
to create an instance?
We've all done it ...
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list