zoukankan      html  css  js  c++  java
  • python note of decorator


    def decorate_log(decorate_arg,*args,**kwargs): # 存放装饰器参数
    def decorate_wrapper(func,*args,**kwargs): # 存放函数名
    def wrapper(text,*args,**kwargs): # 存放函数参数
    start_time = time.clock()
    func(text)
    decorate_text = decorate_arg + '+' + text
    print('decorate text: ' + decorate_text)
    print('function %s() spend time: %d'% (func.__name__,int((time.clock()-start_time))))
    # return decorate_text
    return wrapper
    return decorate_wrapper

    @decorate_log('test')
    def func(text):
    time.sleep(3)
    print('func text: '+ text)

    func('ttt')
    func('eee')

    Advanced Uses of Python Decorators

    https://www.codementor.io/sheena/advanced-use-python-decorators-class-function-du107nxsv
  • 相关阅读:
    C# 结构和类
    c# 接口
    C# 抽象类和密闭方法
    C# 虚方法、override和new
    Pullword 分词工具
    tk简单使用
    C# 值传参和引用传参
    C# 枚举类型
    vim笔记
    Git笔记
  • 原文地址:https://www.cnblogs.com/vickey-wu/p/7072031.html
Copyright © 2011-2022 走看看