zoukankan      html  css  js  c++  java
  • 装饰器的修订

    # import time
    #
    # def index():
    # time.sleep(3)
    # print('Welcome to China')
    # def timmer(func):
    # def inner():
    # start = time.time()
    # func()
    # stop = time.time()
    # print('run time is %s' % (stop - start))
    # return inner
    #
    # index=timmer(index)
    # index()
    '''
    Welcome to China
    run time is 3.0002970695495605
    '''
    # 装饰器语法:在被装饰对象正上方一行单独写上@装饰器名
    # import time
    # def timmer(func):
    # def inner():
    # start = time.time()
    # func()
    # stop = time.time()
    # print('run time is %s' % (stop - start))
    # return inner
    # @timmer # 把@装饰器正下方的函数名当作参数传给@装饰器名,并把结果重新命名给index
    # def index():
    # time.sleep(3)
    # print('Welcome to China')
    #
    # index()
    '''
    Welcome to China
    run time is 3.000959634780884
    '''
    # import time
    # def timmer(func):
    # def inner():
    # start = time.time()
    # res=func()
    # stop = time.time()
    # print('run time is %s' % (stop - start))
    # return res
    # return inner
    # @timmer
    # def index():
    # time.sleep(1)
    # print('Welcome to China')
    # return 521
    #
    # res=index()
    # print(res)
    '''
    Welcome to China
    run time is 1.0006263256072998
    521
    '''
    # import time
    # def timmer(func):
    # def inner(*args,**kwargs):
    # start = time.time()
    # res=func(*args,**kwargs)
    # stop = time.time()
    # print('run time is %s' % (stop - start))
    # return res
    # return inner
    # @timmer
    # def home(name):
    # print('Welcome %s to China'%name)
    #
    # home('Rambo')
    '''
    Welcome Rambo to China
    run time is 0.0
    '''
    # 有参装饰器
    # import time
    # def auth(func):
    # # func=index
    # def inner(*args,**kwargs):
    # name=input('>>:name').strip()
    # password=input(">>:paseword").strip()
    # if name == "Rambo" and password == '123':
    # print('登录成功')
    # return func(*args,**kwargs)
    # else:
    # print('用户名或者密码错误')
    # return inner
    # @auth
    # def index(name):
    # time.sleep(1)
    # print('Welcome %s to China'%name)
    # return 521
    #
    # res=index('Rambo')
    # print(res)
  • 相关阅读:
    html HTML 文本格式化
    纯css3实现图片切换
    绝对路径和相对路径
    CSS设置html网页背景图片 CSS设置网页背景颜色
    使用CSS3制作响应式网页背景图像
    CSS背景全攻略
    HTML中通过CSS设置背景图片自适应浏览器大小
    CSS设置背景——图片背景
    如何让图片自适应手机等移动设备屏幕大小
    SERVER 2012 R2 对域用户禁用移动存储设备
  • 原文地址:https://www.cnblogs.com/0B0S/p/11979341.html
Copyright © 2011-2022 走看看