Python 装饰器示例

 1 #!/usr/bin/env python
 2 # _*_ coding: UTF-8 _*_
 3 # Author:taoke
 4 def applePrice(func):
 5     def otherfunc():
 6         print("apple : 5$")
 7         func()
 8     return otherfunc
 9 
10 @applePrice
11 def displayApple():
12     print("apple : red")
13 
14 displayApple()

apple : 5$
apple : red

原文地址:https://www.cnblogs.com/taoke2016/p/7471399.html