Inheriting from object

Robert Kern rkern at ucsd.edu
Wed Jun 29 15:08:39 EDT 2005


Fuzzyman wrote:
> Hello,
> 
> To create a classic (old style) class, I write :
> 
> class foo:
>     pass
> 
> To do the equivalent as a new style class, I write :
> 
> class foo(object):
>     pass
> 
> *Should* I in fact write :
> 
> class foo(object):
>     def __init__(self, *args, **kwargs):
>         object.__init__(self)
> 
> ?

I don't believe so.

> Also, can anyone explain any tangible benefit of inheriting from
> object, when not explicitly using any features of new style classes ?

This class might not, but you (or someone else) may decide later to 
subclass it and want to use those features. It's a good habit to get 
into even if you don't initially plan on using those features.

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the Python-list mailing list