Reputation: 669
When creating a class in python should it inherit from object or Object, or neither? Is there any need to inherit from object at all?
class NewClass(object)
or
class NewClass(Object)
or
class NewClass()
Upvotes: 4
Views: 240
Reputation: 6366
A class inherits from object
if it 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:
Python Documentation - Type and Class Changes
Object
, on the other hand, seems to be a poorly named variable or object.
Upvotes: 5