You are here:About>Computing & Technology>Python> Beginning Python> Python's Function Decorators: A History of classmethod()
About.comPython
Newsletters & RSSEmail to a friendSubmit to Digg

Python Decorators, Methods, and Functions

From Al Lukaszewski,
Your Guide to Python.
FREE Newsletter. Sign Up Now!

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.]

  1. Python's Function Decorators: An Introduction
  2. Python Decorator Precursors: A History of Python's staticmethod()
  3. Python Decorator Precursors: A History of Python's classmethod()
  4. Redirecting Python Calls to Functions and Methods
  5. Defining the Decoration
  6. Decorating Functions in Python
  7. Output of the Decorated Functions

<< Previous | Next >>

 All Topics | Email Article | | |
Advertising Info | News & Events | Work at About | SiteMap | Reprints | HelpOur Story | Be a Guide
User Agreement | Ethics Policy | Patent Info. | Privacy Policy©2008 About, Inc., A part of The New York Times Company. All rights reserved.