1. Technology

Python Decorators, Methods, and Functions


2 of 7

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

In Python 2.2, Python's function object model was extended to include a differentiation between methods: static and class. Methods that are static are not referenced outside of the class's methods and attributes. Because they do not interact with the world outside the class, they are consider immutable. To assign this immutability to the method, one used the method staticmethod():

 class Class: 
 Â Â Â Â def method() 
 Â Â Â Â Â Â Â Â ... 
 Â Â Â Â method = staticmethod(method) 
Because static methods never reference and are never referenced outside of the class, they have no need for a self parameter.

[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. About.com
  2. Technology
  3. Python
  4. Beginning Python
  5. Python's Function Decorators: A History of staticmethod()

©2014 About.com. All rights reserved.