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
?
Asked
Active
Viewed 209 times
3

Karl Knechtel
- 62,466
- 11
- 102
- 153

Pushpak Dagade
- 6,280
- 7
- 28
- 41
-
This is not quite a duplicate, but please refer to http://stackoverflow.com/questions/54867/old-style-and-new-style-classes-in-python . – Karl Knechtel Jan 08 '11 at 15:53
-
possible duplicate of [python class inherits object](http://stackoverflow.com/questions/4015417/python-class-inherits-object) – Jan 08 '11 at 16:59
-
you can find this easily by searching for "python inherit from object" – Jan 08 '11 at 17:00
2 Answers
7
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.

unutbu
- 842,883
- 184
- 1,785
- 1,677
0
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

virhilo
- 6,568
- 2
- 29
- 26