1. Home
  2. Computing & Technology
  3. Python

Python Decorators, Methods, and Functions

From , former About.com Guide

3 of 7

Python Decorator Precursors: A History of Python's classmethod()

After Python 2.2, methods that received the class itself as an argument were classified as class methods. They were then definable with the classmethod() method.

class Class:
     def method(cls)
         ...
     method = classmethod(method)
By convention, the argument which holds the class is always the first and is called cls.

Once again, this is for illustration only. After a spirited discussion on the Python language discussion group, a formal syntax has been incorporated for these two methods, and it is called a decorator.

[Note: This code is for illustration only. As we are about to see, this syntax has now changed. Of course, Python offers backward compatability for a few versions, but you should use the new syntax, not this.]

Explore Python
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Python
  4. Beginning Python
  5. Python's Function Decorators: A History of classmethod()

©2009 About.com, a part of The New York Times Company.

All rights reserved.