• Python_装饰器复习_30


    复习:

    # 装饰器的进阶
    # functools.wraps
    # 带参数的装饰器
    # 多个装饰器装饰同一个函数
    # 周末的作业
    # 文件操作
    # 字符串处理
    # 输入输出
    # 流程控制

    # 装饰器
    # 开发原则 : 开放封闭原则
    # 装饰器的作用 :在不改变原函数的调用方式的情况下,在函数的前后添加功能
    # 装饰器的本质 : 闭包函数

    def wrapper(func):
        def inner(*args,**kwargs):
            print('在被装饰的函数执行之前做的事')
            ret = func(*args,**kwargs)
            print('在被装饰的函数执行之后做的事')
            return ret
        return inner
    
    @wrapper   #holiday = wrapper(holiday)
    def holiday(day):
        print('全体放假%s天'%day)
        return '好开心'
    
    ret = holiday(3)
    print(ret)
    def outer(*args):
        print(args)
        print(*args)
        
    
    
    outer(1,2,3,4)
    
    # (1, 2, 3, 4)
    # 1 2 3 4
    def outer(*args):
        print(args)
        print(*args)
        def inner(*args):
            print('inner : ',args, *args)
        inner(*args)
    
    
    outer(1,2,3,4)   #==outer(*[1,2,3,4])  #==outer(*(1,2,3,4))
    
    
    
    #(1, 2, 3, 4)
    #1 2 3 4
    #inner :  (1, 2, 3, 4) 1 2 3 4

     

  • 相关阅读:
    dos命令大全
    死亡之ping(Ping of Death)
    硬盘安装系统
    DataGrid实现逻辑分页
    DropDownList另一种写法
    DataGrid3
    DataGrid2
    hidden(隐藏域)
    sql合并列
    未找到与约束contractname Microsoft.VisualStudio.Utilities.IContentTypeRegistryService...匹配的导出
  • 原文地址:https://www.cnblogs.com/LXL616/p/10665550.html
Copyright © 2020-2023  润新知