[Tutor] Inheritance : what am I doing wrong?
Emmanuel Ruellan
eruellan@iFrance.com
Sat Nov 30 18:43:01 2002
In reply to a message I sent, explaining that...
> > I'm having a problem with inheritance.
...Alan Gauld wrote :
>
> I don't think so :-)
>
There _is_ an inheritance issue here : I've checked the archives
of the Visual Python mailing list (should have done that
first...) and found out that the objects of the visual module
just couldn't be subclassed. Weird.
> > class ball(visual.sphere):
> > def __init__(self):
> > visual.sphere.__init__(self, radius = 0.5)
>
> You shouldn't be able to do that.
> You must set radius outside the call to the function.
I don't understand why I couldn't use this syntax
(name=parameter) with a constructor.
However, I've found out that visual.sphere.__init__() cannot work
properly as a constructor because, despite all appearances,
visual.sphere is not a class!
>>> type(visual.sphere)
<type 'instance'>
>>> visual.sphere.__init__
<bound method _o_constructor.__init__ of <built-in method sphere of
tuple object at 0x009CC420>>
It appears that Visual mimics the behaviour of a sphere class
with... something else. This confuses me. Anyway, I can go on
using a sphere 'object' as an attribute for ball objects, instead
of deriving a ball class from a sphere class as I intended to.
Thanks for your help,
Manu