简而言之,答案就是这个对象。方法只检查是否没有参数被传入。有关详细信息,请参见the source。
当对服务的实例调用时,
然而,当对服务的子类的实例调用时,事情变得更加有趣。super()调用可能会委托给object以外的某个类,该类是实例的父类,但不是Service的父类。有关如何工作以及为什么有用的详细信息,请参阅博客文章Python's Super Considered Super!
下面的示例(有点做作)显示了服务的子类如何导致super调用服务被指向另一个名为Color的类:class Service(object):
def __init__(self, host, binary, topic, manager, report_interval=None,
periodic_interval=None, *args, **kwargs):
print 'Initializing Service'
super(Service, self).__init__(*args, **kwargs)
class Color(object):
def __init__(self, color='red', **kwargs):
print 'Initializing Color'
self.color = color
super(Color, self).__init__(**kwargs)
class ColoredService(Service, Color):
def __init__(self, *args, **kwds):
print 'Initializing Colored Service'
super(ColoredService, self).__init__(*args, **kwds)
c = ColoredService('host', 'bin', 'top', 'mgr', 'ivl', color='blue')
在示例中,初始化按以下顺序进行:初始化有色服务
正在初始化服务
初始化颜色
初始化对象——除了参数检查之外什么都不做