[Tutor] which gets called
Mark Lawrence
breamoreboy at yahoo.co.uk
Fri Apr 6 17:07:34 CEST 2012
On 06/04/2012 14:54, John Fabiani wrote:
> Hi,
>
> I want to create a class that inherits two other classes.
>
> class NewClass( A,B)
>
> But both "A" and "B" contain a method with the same name ("onKeyDown").
>
> If my "NewClass" does not contain something to override the methods which one
> would be called if
>
> myinstance = NewClass()
>
> myinstance.onKeyDown()
>
Please see
http://docs.python.org/tutorial/classes.html#multiple-inheritance. This
references http://www.python.org/download/releases/2.3/mro/ Having read
these why not try typing code into the interactive prompt and see what
happens? Worst case you get an exception, if you don't understand it
cut and paste it to a reply to this and we'll help out.
>
> Second to insure the right one is called is it possible to do the following
>
> NewClass(object):
>
> def onKeyDown(self, event):
> b.onKeyDown(event)
It's B.onKeyDown(self, event), without the self you'll get an unbound
method error.
>
> Johnf
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
--
Cheers.
Mark Lawrence.
More information about the Tutor
mailing list