1. Home
  2. Computing & Technology
  3. Python

Python Decorators, Methods, and Functions

From , former About.com Guide

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.

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 Function Decorators: Output of the Decorated Functions

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

All rights reserved.