Newsgroups: comp.lang.python
From: Laszlo Zsolt Nagy <gand...@geochemsource.com>
Date: Wed, 18 May 2005 15:18:01 +0200
Local: Wed, May 18 2005 9:18 am
Subject: Re: super() and automatic method combination
>I have the impression that this is supposed to call the f method instance. > A Correct. When you use super(B,self) it accesses the current instance as > B > C >or maybe > B > A > C >depending on the resolution order. However, it only calls A.f and not B.f. >I also notice that if I say > class B(object): >then the class B. If it has no method named 'f' then this will end up in an exception. >That doesn't seem like such a good thing necessarily. But yes, it is. When you try to call a nonexistent method, it should raise an exception. >Anyway, is there a preferred way of writing this example so that C.f I do not know a preferred way. However, I made this example for you, I >automatically calls both A.f and B.f? hope it helps. class CallSupersMixin(object): class A(object): class B(object): class AB(A,B,CallSupersMixin): ab = AB() Of course you can remove the "raise AttributeError" part. Then it will Laci 2.0 -- Python forever! You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||