why python 2.7 define class without inheriting object would not have __mro__ method?
本问题已经有最佳答案,请猛点这里访问。
我正在用Python2.7.9开发MacOSXyosemite。
以下是我的尝试:
定义一个类
1 2 3  | class A: def test(self): print"test"  | 
然后运行
1  | A.__mro__  | 
然后我得到了
1 2 3 4  | >>> A.__mro__ Traceback (most recent call last): File"<stdin>", line 1, in <module> AttributeError: class A has no attribute '__mro__'  | 
然后我定义
1 2 3  | class B(object): def test(self): print"test"  | 
然后运行
1  | B.__mro__  | 
然后我得到了
1 2  | >>> B.__mro__ (<class '__main__.B'>, <type 'object'>)  | 
这两种定义有什么不同?我发现在python3中,没有"object"的版本仍然有
在python 3中,所有类都是新样式的类。他们含蓄地继承了以东的遗产。换句话说,已经从语言中删除了旧式的python 2类。