1. Technology

Python Decorators, Methods, and Functions


7 of 7

Output of the Decorated Functions

When the decorated function is called, the focus of Python is redirected to the decorating function. The decorator becomes a wrapper around the function. So, the name of the function that is called remains as the identity of the function, even when it is referenced by the decorating function.

 >>> a.attribute 
 'I live to decorate a' 
 >>> b.mantra 
 'My existence is as an ornament for b' 
 >>> c.attribute 
 'I live to decorate c' 
 >>> c.mantra 
 'My existence is as an ornament for c' 
Decorators are thus a very elegant way of combining methods and functions without having to re-arrange someone else's code.

In addition to the information presented here, on the Python Software Foundation's website you can find the proposal that lead to decorators, PEP 318, and the introductory discussion about them that accompanied Python 2.4.

  1. About.com
  2. Technology
  3. Python
  4. Beginning Python
  5. Python Function Decorators: Output of the Decorated Functions

©2014 About.com. All rights reserved.