相关疑难解决方法(0)

是否可以使用Python进行部分继承?

我正在Python中创建一个类(class0),它目前基于一个类(class1); 但是,我也希望从另一个类继承(class2).关于class2的事情是我不想要它的所有方法和属性,我只需要一个方法.class0是否可以仅从class2继承单个方法?

python inheritance class

18
推荐指数
3
解决办法
4949
查看次数

如何执行部分继承

我有两个类,例如:

class Parent(object):

    def hello(self):
        print 'Hello world'

    def goodbye(self):
        print 'Goodbye world'


class Child(Parent):
    pass
Run Code Online (Sandbox Code Playgroud)

class Child必须只从Parent继承hello()方法,并且不应该提及goodbye().可能吗 ?

ps是的,我读过这个

重要说明:我只能修改Child类(在所有可能的父类中应保留原样)

python inheritance

3
推荐指数
1
解决办法
1977
查看次数

标签 统计

inheritance ×2

python ×2

class ×1