Inheritance but only partly?

Matimus mccredie at gmail.com
Thu Oct 2 22:44:13 CEST 2008


On Oct 2, 1:16 pm, process <circularf... at gmail.com> wrote:
> Let's say I have a class X which has 10 methods.
>
> I want class Y to inherit 5 of them.
>
> Can I do that? Can I do something along the lines of super(Y, exclude
> method 3 4 7 9 10) ?

I think the noral way of doing that is to split the origional class
into two classes.

What you have:

class BaseClass(object):

    def method0:
        pass

    def method1:
        pass

    def method2:
        pass

    ...

    def method9:
        pass

What you need:


class BaseClassWant(object):
    def method0:
        pass

    def method1:
        pass

    ...

    def method4:
        pass

class BaseClassDontWant(object):
    def method5:
        pass

    def method6:
        pass

    ...

    def method9:
        pass

class BaseClass(BaseClassWant, BaseClassDontWant): # same as BaseClass
above
    pass

class YourClass(BaseClassWant):
    pass


Matt



More information about the Python-list mailing list