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

    # 开放封闭原则:对扩展是开放,对修改是封闭
    # 装饰器:装饰她人的,器指的是任意可调用对象,现在的场景装饰器>>:函数,被装饰的对象也是函数
    # 原则:不修改被装饰对象的的源代码
    # 不修改被装饰对象的调用方式
    # 装饰器的目的,在遵循原则的前提下,为被装饰对象添加上新功能
    # import time
    #
    # def index():
    # time.sleep(3)
    # print('Welcome to China')
    #
    # start=time.time() # 时间戳,显示的是以秒为单位的时间
    # index()
    # stop=time.time()
    # print('run time is %s'%(stop-start))
    '''
    Welcome to China
    run time is 3.000962257385254
    '''
    # import time
    #
    # def index():
    # time.sleep(3)
    # print('Welcome to China')
    # def timmer(func):
    # start = time.time() # 时间戳,显示的是以秒为单位的时间
    # func()
    # stop = time.time()
    # print('run time is %s' % (stop - start))
    #
    # timmer(index)
    '''
    Welcome to China
    run time is 3.0009765625
    '''
    # import time
    #
    # def index():
    # time.sleep(3)
    # print('Welcome to China')
    # def outter(func):
    # def timmer():
    # start = time.time()
    # func()
    # stop = time.time()
    # print('run time is %s' % (stop - start))
    # return timmer
    #
    # f=outter(index)
    # print(f)
    # f()
    # '''
    # <function outter.<locals>.timmer at 0x000002314AB24DC8>
    # Welcome to China
    # run time is 3.0000648498535156
    # '''
  • 相关阅读:
    带锚点URL同一页面滚动效果的实现
    思路先行
    transliteration -- 2个功能
    html5 section article
    fields('t')
    使用Bootstrap
    JavaScript Switch
    菜单
    写一个博客页面
    自动适应
  • 原文地址:https://www.cnblogs.com/0B0S/p/11974571.html
Copyright © 2011-2022 走看看