python 项目实战之装饰器

 1 import logging
 2 
 3 def use_logging(func):
 4     def writelog(*args, **kwargs):
 5         logging.warning("%s is running xxx" % func.__name__)
 6         return func(*args)
 7 
 8     return writelog
 9 
10 def far():
11     print("far....")
12 
13 @use_logging
14 def bar():
15     print("装饰器")
16 
17 if __name__ == '__main__':
18 
19     far = use_logging(far)
20     far()
21     bar()

 

posted @ 2019-10-15 14:00  Mr.zou  阅读(272)  评论(0编辑  收藏  举报