The decorator must be a callable object (either a function or an object that implements __call__), where the parameter is a decorated function, and the result is a function that replaces the function that was decorated, therefore, to use your print example 'sss' instead of printing' aaa ':
>>> def a (f):
... def replacementfunc ():
... print 'sss'
... return replacementfunc;
...
>>> @a
... def b ():
... print 'aaa'
...
>>> b ()
sss
Or a more complex example:
>>> class print_decorator (object):
... def __init __ (self, text):
... self.text = text;
... def __call __ (self, f):
... def replacement ():
... print self.text;
... return replacement;
...
>>> @print_decorator ("Hello world!")
... def b ():
... print 'aaa';
...
>>> b ()
Hello world!
Edit
As for your updated question, you need to look at the documentation for @property . It is not clear what exactly you are trying to execute, although I assume that you want:
class a:
@property
def b (self):
return 'sss'
aa = a ()
print aa.b # prints 'sss', whereas without @property, prints <function ...>
source share