zoukankan      html  css  js  c++  java
  • python 装饰器

    import time 
    
    def decorator(func):
        def wrapper():
            print time.time()
            func()
        return wrapper
    
    def f1():
        print('xxxxxx')
    
    f= decorator(f1)
    f()

    import time 
    
    def decorator(func):
        def wrapper():
            print time.time()
            func()
        return wrapper
    
    @decorator
    def f1():
        print('xxxxxx')
    
    f1()

    import time 
    
    def decorator(func):
        def wrapper(name):
            print time.time()
            func(name)
        return wrapper
    
    @decorator
    def f1(name):
        print('xxxxxx'+name)
    
    f1('eeeee')

    import time 
    
    def decorator(func):
        def wrapper(*args):
            print time.time()
            func(*args)
        return wrapper
    
    @decorator
    def f2(n,m):
        print('xxxxxx'+n+m)
    
    f2(1,3)

    import time 
    
    def decorator(func):
        def wrapper(*args,**kw):
            print time.time()
            func(*args,**kw)
        return wrapper
    
    @decorator
    def f3(n,m,**kw):
        print('xxxxxx'+n+m)
        print(kw)
    f3(1,3,n=2,e=3)
  • 相关阅读:
    JS小功能系列9商品筛选
    JS小功能系列8省市联动
    if u
    js属性
    js初识
    弹性盒
    项目合作
    css重置
    关于响应式布局
    自我定位
  • 原文地址:https://www.cnblogs.com/angdh/p/11723308.html
Copyright © 2011-2022 走看看