class BaseOne(object):
def base_one(self):
print self.first
print self.second
# Do stuffs with self.first and self.second defined from sub class
class BaseTwo(object):
def base_two(self):
print self.first
print self.second
# Do stuffs with self.first and self.second defined from sub class
class Stackoverflow(BaseOne, BaseTwo):
def __init__(self):
super(Stackoverflow, self).__init__()
self.first = 'Stack'
self.second = 'Overflow'
class Serverfault(BaseOne, BaseTwo):
def __init__(self):
super(Serverfault, self).__init__()
self.first = 'Server'
self.second = 'Fault'
Stackoverflow().base_one()
Serverfault().base_one()
在BaseOne
orBaseTwo
中,我想使用从子类定义的变量。有没有更好的方法来完成上述操作?