Python 装饰器

__author__ = 'Brook Zhao'
import time
def login(cus_type):
    def runfunc(func):
        def kenner(*args,**kwargs):
            variable01=time.time();
            print("Customer Type:%s"%cus_type)  #对传入的用户类型进行处理
            result=func(*args,**kwargs)     #被装饰函数实体运行
            variable02=time.time();
            return result   #返回被装饰函数的返回值
        return kenner   #返回函数地址
    return runfunc      #返回函数地址

@login("qq")
def test001(a,b,c):
    print("in the test001 case")
    time.sleep(1)
    return (a+b+c)/3

@login("weixin")
def test002():
    print("in the test002 case,the case no return value")
    time.sleep(1)

result=test001(1,2,3)
print(result)
test002()

*************RESULT***************

Customer Type:qq
in the test001 case
2.0
Customer Type:weixin
in the test002 case,the case no return value

转载于:https://www.cnblogs.com/HappyBing/p/9777457.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值