超级(类型,对象

    class B1(object):
        def f(self):
            print "B1.f"

    class B2(object):
        def f(self):
            print "B2.f"

    class D(B1, B2):
        pass

    d = D()
    super(B1, d).f()
    print B1.__mro__

为什么要打印上面的代码:

B2.f
(<class '__main__.B1'>, <type 'object'>)

而文档http://docs.python.org/2/library/functions.html#super说:

super(type[, object-or-type]):
... The __mro__ attribute of the type lists the method resolution search order used by ... super(). 

似乎使用的MRO不是super()的“type”参数之一,而是“object-or-type”参数之一。 这是Python文档中的错误吗?

链接地址: http://www.djcxy.com/p/54791.html

上一篇: super(type, object

下一篇: Clear terminal in Python