首页 > 编程语言 > 详细

Python 装饰器

时间:2018-06-23 20:11:54      阅读:226      评论:0      收藏:0      [点我收藏+]
#一、装饰器的作用就是给已经实现的功能再扩展新的功能
#二、无参数的
# def wohaoshuai1(func):
# print("wohaoshuai1")
# return func
#
# @wohaoshuai1
# def wohaoshuai2():
# print("wohaoshuai2")
#
# # 与上面装饰内容原理相同
# # wohaoshuai2 = wohaoshuai1(wohaoshuai2)
# wohaoshuai2()

#三、有参数
# def wohaoshuai1(function):
# def inner(*args,**kwargs):
# print("wohaoshuai1")
# return function(*args,**kwargs)
# print(inner)
# return inner
#
# @wohaoshuai1
# def wohaoshuai2(name,wohaoshuai,c):
# print("wohaoshuai2 {0} {1} {2}".format(name,wohaoshuai,c))
# return 1
#
# print(wohaoshuai2)
# a = wohaoshuai2("aaa","bbb",c=1)
# print(a)
#
# <function wohaoshuai1.<locals>.inner at 0x05536108>
# <function wohaoshuai1.<locals>.inner at 0x05536108>
# wohaoshuai1
# wohaoshuai2 aaa bbb 1
# 1

Python 装饰器

原文:https://www.cnblogs.com/Presley-lpc/p/9218190.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!