Classes, virtual methods ?

Fredrik Lundh fredrik at pythonware.com
Fri May 16 04:27:11 EDT 2003


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

> if you have :
>
> Class A:
>    def foo():
>        print "in class A"

I suppose you really meant:

    class A:
        def foo(self):
            print "in class A"

> Class B(A):
>    def foo()
>        print "in class B"
>
> m = B()
> print m.foo()
>
> You get 'in class B'
>
> Now my question
>
> Is there a way of calling foo of the master class of B with an instance of B

instead of

    m.foo()

use

    A.foo(m)

> I think this is called virtual methods ?

I think you have that slightly backwards (in Python, all methods
are virtual).

</F>








More information about the Python-list mailing list