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

posted @ 2017-09-03 22:17  饕客  阅读(108)  评论(0编辑  收藏  举报