python decorater working priciple

来源:互联网 发布:如何应对网络谣言 编辑:程序博客网 时间:2024/05/01 09:11
from flask import Flask
@app = Flask('/')
def hello():
return'hello word!'   
#I will tell you how to understand the  decorater @app = Flask('/') and it's working priciple:
#for axample of a decorater:
def my_decorater(f):
def wrapper():
print "starting : my name is xxx"
f()
print"ending :  xxx is my name"

return wrapper


@my_decorater#equal to  hello = my_decorater(hello)
def  hello ():
print "hello world"
hello()
#'''the output is "starting : my name is xxx
                        hello world
                        ending :  xxx is my name"  '''
原创粉丝点击