super()用于调用派生类中重新定义的基类方法。如果您的类正在定义append()和popleft()扩展其行为的方法,那么在super()内部使用append()and是合理的popleft()。但是,您的示例没有从 重新定义任何内容deque,因此不需要super().
以下示例显示了何时super()使用:
class Queue(deque):
def append(self, a):
# Now you explicitly call a method from base class
# Otherwise you will make a recursive call
super(Queue, self).append(a)
print "Append!!!"
然而,在多重继承的情况下,super()比仅仅允许从基类调用方法更复杂。详细了解需要了解MRO(方法解析顺序)。因此,即使在上面的示例中,通常最好这样写:
class Queue(deque):
def append(self, a):
# Now you explicitly call a method from base class
# Otherwise you will make a recursive call
deque.append(self, a)
print "Append!!!"