Selective Inheritance Python

Posted by user1682595 on Stack Overflow See other posts from Stack Overflow or by user1682595
Published on 2012-09-19T09:23:23Z Indexed on 2012/09/19 9:37 UTC
Read the original article Hit count: 523

Filed under:

I am making a python program which is using classes, I want one class to only selectively inherit from another e.g:

class X(object):
    def __init__(self):
        self.hello = 'hello'

class Y(object):
    def __init__(self):
        self.moo = 'moo'

class Z():
    def __init__(self, mode):
        if mode == 'Y':
             # Class will now Inherit from Y
        elif mode == 'X':
             # Class will now Inherit for X

How can I do this without making another class?

© Stack Overflow or respective owner

Related posts about python