|
发表于 2020-6-3 09:53:42
|
显示全部楼层
class PlugIn(object):
def __init__(self):
self._exported_methods = []
def plugin(self, owner):
for f in self._exported_methods:
owner.__dict__[f.__name__] = f
def plugout(self, owner):
for f in self._exported_methods:
del owner.__dict__[f.__name__]
class AFeature(PlugIn):
def __init__(self):
super(AFeature, self).__init__()
self._exported_methods.append(self.get_a_value)
def get_a_value(self):
print 'a feature.'
class BFeature(PlugIn):
def __init__(self):
super(BFeature, self).__init__()
self._exported_methods.append(self.get_b_value)
def get_b_value(self):
print 'b feature.'
class Combine:pass
c = Combine()
AFeature().plugin(c)
BFeature().plugin(c)
c.get_a_value()
c.get_b_value()
问:super(AFeature, self)和super(BFeature, self)这两个参数为什么要放,我改成super().__init__() 运行结果是一样的,请问这里有什么区别呢?????? |
|