subclass of object

Steve Holden steve at holdenweb.com
Fri Apr 2 13:57:35 CEST 2010


Jason Friedman wrote:
> Hi, what is the difference between:
> 
> def MyClass(object):
>     pass
> 
> and
> 
> def MyClass():
>     pass

In Python 3, nothing. In Python 2, the former gets you a subclass of
object whereas the latter gets you an instance of <type 'classobj'>, for
compatibility with pre-2.2 versions.

For most practical purposes there is no difference, so it doesn't matter
until it matters, so to speak. Unless you are noticing unexpected
behavior in your programs you probably don't need to worry (though you
might want to use the first form to ensure better Python 3 compatibility).

regards
 Steve
-- 
Steve Holden           +1 571 484 6266   +1 800 494 3119
See PyCon Talks from Atlanta 2010  http://pycon.blip.tv/
Holden Web LLC                 http://www.holdenweb.com/
UPCOMING EVENTS:        http://holdenweb.eventbrite.com/




More information about the Python-list mailing list