OOP - Is this right or is it a bug ?

Fredrik Lundh fredrik at pythonware.com
Tue May 20 03:23:40 EDT 2003


"Rony" <rony.steelandt at bucodi.com> wrote:

> Not specialised in OOP, but learning, i discovered something by coinsidence
> If you do
>
> Class A:
>    def foo(self):
>       print 'in A'
>
> Class B:
>    def foo(self):
>       print 'in B'
>
> Then you do
>
> Class C(A,B):
>    def other(self):
>       nop
>
> m=C()
> print m.foo()
>
> You get 'in A'
>
> I tought you would get 'in B' since you first heritate from A and the from B

this means that Python will look in A *before* looking in B.

in this case, A has a "foo", so Python doesn't even bother to look in
B, and you'll end up calling "A.foo".

> I suppose i miss something here ?
> Can somebody explain to me ?

this is (briefly) discussed in the tutorial:

http://www.python.org/doc/current/tut/node11.html#SECTION0011510000000000000000

</F>








More information about the Python-list mailing list