Old-style and new-style classes in Python 2.7 [duplicate] Old-style and new-style classes in Python 2.7 [duplicate] python python

Old-style and new-style classes in Python 2.7 [duplicate]


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.


You should always use new style classes. New-style classes are part of an effort to unify built-in types and user-defined classes in the Python programming language.

New style classes have several things to offer such as:

  • Properties: Attributes that are defined by get/set methods
  • Static methods and class methods
  • The new getattribute hook, which, unlike getattr, is calledfor every attribute access, not just when the attribute can’t befound in the instance
  • Descriptors: A protocol to define the behavior of attribute accessthrough objects
  • Overriding the constructor new
  • Metaclasses

Source.