在软件开发的过程中,要遵循软件的一些原则封装的,不改变原有的代码的基础增加一些需求,python提供了装饰器来扩展函数功能,下面说说函数装饰器用法
def debug(func):
def wrapper():
print "[DEBUG]: enter {}()".format(func.__name__)
return func()
return wrapper
@debug #
def say_hello():
print "www.96net.com.cn"
函数的装饰器用的函数
1,闭包函数
内部返回一个函数名
2,高阶函数
把函数当成参数传递
3,嵌套函数
函数里面嵌套函数
文章来自 http://www.96net.com.cn