July 2014
def identity_decorator(func):
def wrapper():
func()
return wrapper
def a_function():
print "I'm a normal function."
decorated_function = identity_decorator(a_function)
decorated_function()
I'm a normal function.
@identity_decorator
def another_decorated_function():
print "I too am a normal function"
another_decorated_function()
I too am a normal function
Using the @
and placing it before the function to be decorated puts it in-your-face.
Highlights the function modification instead of burying it at the end as a variable assignment.
@dec2
@dec1
def function1():
pass
equivalent to
def function1():
pass
func = dec2(dec1(function1))
You can do it.
def increment(val):
return val + 1
increment(1)
2
@click.command
@app.route