Old-style and new-style classes in Python 2.7

User picture User · Dec 11, 2012 · Viewed 8.3k times · Source

Possible Duplicate:
Old style and new style classes in Python

What is the current state of affairs with new-style and old-style classes in Python 2.7?

I don't work with Python often, but I vaguely remember the issue. The documentation doesn't seem to mention the issue at all: The Python Tutorial: Classes. Do I still need to worry about this? In general, should I declare my classes like the following?

class MyClass:
    pass

or?

class MyClass(object):
    pass

Answer

Reinout van Rees picture Reinout van Rees · Dec 11, 2012

Always subclass "object". Those are new style classes.

  • You are ready for Python 3 that way.

  • Things like .super() work properly that way, should you need them.