2 Respostas
+ 3
In general means that annotation is used on defined object (class or function).
For instance, there is annotation "property" which let's you define custom behavior while getting something.
python2:
class foo(object):
def __init__(self):
self._value = 5
@property
def value(self):
print "getting value.."
return self._value
f = foo()
print f.value
above will print:
getting value..
5
There are many different annotations out there and you can define even your own.
This is how you create your own annotation:
def double_result(f):
def wrapper():
result = f()
return result*2
return wrapper
@double_result
def my_super_complex_function():
return 5
print my_super_complex_function()
above will print "10"
You can also use multiple annotations on one object.
@double_result
@double_result
def bar():
return 3
print bar()
above will print 12 (3*2*2)
+ 1
Oh cool. Thanks!