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++学习网址
    python学习网址
    python之raw_input()函数
    APP营销模式
    计划任务
    多线程
    Spring Aware
    事件(Application Event)
    Spring 的AOP
    Java配置
  • 原文地址:https://www.cnblogs.com/vickey-wu/p/7072031.html
Copyright © 2011-2022 走看看