Q? Calling nearest inherited method
Laurent POINTAL
pointal at lure.u-psud.fr
Wed May 17 08:54:11 EDT 2000
On Wed, 17 May 2000 11:54:53 +0000 (GMT), Oleg Broytmann
<phd at phd.russ.ru> wrote:
>: On Wed, 17 May 2000, Laurent POINTAL wrote:
>: > Given a class hierarchy like this:
>: > A
>: > B inherits A
>: > C inherits B
>: >
>: > A define dothis method.
>: > C define dothis method.
>: >
>: > In the C.dothis, I wants to call my nearest parent class dothis
>: > method. That is, call B.dothis if it is defined, or A.dothis if it is
>: > defined...
>:
>: I think B.dothis() will do it just right, no?
I was afraid it resolve in a single (B) method search... but it search
also in B parents (even when prefixed explicitely with B).
Thanks.
Python is really wonderful.
A+
Laurent.
Here is a small test:
>>> class A :
... def dothis(self) :
... print "In A.dothis()"
...
>>> class B(A) :
... pass
...
>>> class C(B) :
... def dothis(self) :
... print "In C.dothis()"
... B.dothis(self)
...
>>>
>>> c=C()
>>> c.dothis()
In C.dothis()
In A.dothis()
---
Laurent POINTAL - CNRS/LURE - Service Informatique Experiences
Tel/fax: 01 64 46 82 80 / 01 64 46 41 48
email : pointal at lure.u-psud.fr ou lpointal at planete.net
More information about the Python-list
mailing list