Here is an example to illustrate:
#coding: Utf-8
"""
The function of the Foo = decorator (foo) statement is to pass the Foo function as a parameter to the decorator
The return value is assigned to Foo, so Foo is no longer the original function.
To simplify the code, Python adds an adorner to this syntactic sugar
Makes
@decorator
def foo ():
Print ("Welcome to Huanggo Python training")
Print ("Consulting qq:1465376564")
Print ("Https://github.com/pythonpeixun/article/blob/master/index.md")
The same effect as Foo = decorator (foo)
"""
def decorator (func):
def inner ():
Print ("Begin func Call")
Func ()
Print ("After func call")
return inner
def foo ():
Print ("Welcome to Huanggo Python training")
Print ("Consulting qq:1465376564")
Print ("Https://github.com/pythonpeixun/article/blob/master/index.md")
@decorator
Def foo2 ():
Print ("Welcome to Huanggo Python training")
Print ("Consulting qq:1465376564")
Print ("Https://github.com/pythonpeixun/article/blob/master/index.md")
foo = decorator (foo)
Foo ()
Print ("***************************")
Foo2 ()
Huanggo Python Remote Video training course
Https://github.com/pythonpeixun/article/blob/master/index.md
Huanggo Python training preview video playback address
Https://github.com/pythonpeixun/article/blob/master/python_shiping.md
Huanggo python training _python Beginner's first step
http://www.tudou.com/programs/view/pZvrOt9RlmE/
How to poke a python-programmed layer of paper video
http://www.tudou.com/programs/view/ppJv6Kf08Ac/
Huanggo code to illustrate: Python syntax sugar