Python笔记(28)装饰器应用详解

    技术2026-03-30  15

    #!/user/bin/env python # -*- coding:utf-8 -*- # author:berlin # 实现装饰器知识储备: #1、 函数即“变量”,有时候函数也相当于变量 # 2、高阶函数 # 3、嵌套函数 # 高阶函数+嵌套函数 => 装饰器 import time def timmer(func): def warpper(*args,**kwargs): start_time=time.time() func() stop_time=time.time() print("func函数运行了:%s 秒" %(stop_time-start_time)) return warpper @timmer def test1(): time.sleep(3) print('in the test1') test1()
    Processed: 0.010, SQL: 9