TypeError: Error when calling the metaclass bases Cannot create a consistent method resolution o

Posted 慕小柒

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TypeError: Error when calling the metaclass bases Cannot create a consistent method resolution o相关的知识,希望对你有一定的参考价值。

原本想测试继承,出现了这个错误:

  源代码

 1 class A1(object):
 2     def fo1(self):
 3         print "i\'m A1"
 4 class A2(object):
 5     def fo1(self):
 6         print "i\'m A2"
 7 class B1(A1,A2):
 8     def bar(self):
 9         print "i\'m B1"
10 class B2(A2,A1):
11     def bar(self):
12         print "i\'m B2"
13 class C(B1,B2):#提示出现错误的地方
14     pass
15 if __name__==\'__main__\':
16     m=C()
17     print C.__mro__
18     m.bar()
19     m.fo1()

错误行数出现在13行,实际就是构图的时候产生了错误,(根据继承先后广搜构图)

此时构图为

显然不能出现俩A1,因此会出现如上的报错

要B都与A有联系只能是下面这种继承构图才不会出错

即将代码修改为

class A1(object):
    def fo1(self):
        print "i\'m A1"
class A2(object):
    def fo1(self):
        print "i\'m A2"
class B1(A1,A2):
    def bar(self):
        print "i\'m B1"
class B2(A1,A2):
    def bar(self):
        print "i\'m B2"
class C(B1,B2):
    pass
if __name__==\'__main__\':
    m=C()
    print C.__mro__
    m.bar()
    m.fo1()

 

以上是关于TypeError: Error when calling the metaclass bases Cannot create a consistent method resolution o的主要内容,如果未能解决你的问题,请参考以下文章

TypeError: member is not a function when using `$member`

TypeError: can't pickle memoryview objects when running basic add.delay(1,2) test

TypeError: _this.store.getState is not a function when using connect from Redux

codeigniter Uncaught TypeError: Cannot use 'in' operator to search 'length' in When theres additiona

$save 给了我 TypeError: undefined is not a function when save model that is a list in angular

Bootstrap:'TypeError undefined is not a function'/'has no method 'tab'' when using bootstrap-tabs