In order to use a decorator, one must first have functions to serve that purpose. Let's create two simple functions, each receives a function as its first and only argument and then creates an attribute for that function object.
>>> def decorate(function): ...Â Â Â Â function.attribute = 'I live to decorate ' + function.__name__ + '.' ...Â Â Â Â return function ... >>> def ornament(function): ...Â Â Â Â function.mantra = 'My existence is as an ornament for ' + function.__name__ + '.' ...Â Â Â Â return function
If you need to refresh yourself on the attributes and methods of function objects, simply type the following at the Python shell prompt (after defining decorate): dir(decorate). One of the attributes is __name__. You will want to pay attention to the value of this attribute in the output of the program.