Reputation: 6460
In python, why is recommended to inherit any class we make from the class object
, why not directly make it as the base class??
An important thing I noticed is that the declaration __slots__
does not work if I make my class as a base class (instead as a subclass of the class object
).
What other advantages/disadvantages do I have by inheriting my class from the class object
?
Upvotes: 3
Views: 229
Reputation: 880667
In Python2, you must inherit from object in order to create a "new-style" class. Things like descriptors, super
and __slots__
do not work correctly with "old-style" classes, but old-style classes remained for backwards compatibility.
In Python3, all classes are new-style classes, so inheriting from object
is no longer necessary.
Upvotes: 7
Reputation: 6793
when you inheriting from the object you create new style class, without it you have old style class see: http://www.python.org/doc/newstyle/ for more
Upvotes: 0