Python class inherits object

后端 未结 6 1039
慢半拍i
慢半拍i 2020-11-21 15:54

Is there any reason for a class declaration to inherit from object?

I just found some code that does this and I can\'t find a good reason why.



        
6条回答
  •  无人共我
    2020-11-21 16:29

    Yes, this is a 'new style' object. It was a feature introduced in python2.2.

    New style objects have a different object model to classic objects, and some things won't work properly with old style objects, for instance, super(), @property and descriptors. See this article for a good description of what a new style class is.

    SO link for a description of the differences: What is the difference between old style and new style classes in Python?

提交回复
热议问题