码迷,mamicode.com
首页 > 编程语言 > 详细

Python 装饰器

时间:2018-06-23 20:57:52      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:turn   **kwargs   function   mat   inner   int   form   war   内容   

#一、装饰器的作用就是给已经实现的功能再扩展新的功能
#二、无参数的
# 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 装饰器

标签:turn   **kwargs   function   mat   inner   int   form   war   内容   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!