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)
  • 相关阅读:
    ArcEngine将对象存储到Blob字段中!
    ArcGIS细节层次(LOD)学习笔记
    ArcSDE Version(版本)学习笔记
    换一种思路:将数据库中的规范数据导入到Geodatabase中
    ArcEngine编辑功能的实现(二)
    ArcEngine编辑功能(一)
    PetShop项目学习笔记(二)
    PetShop项目学习笔记(一)
    BindingSource组件使用
    Oracle10g安装及监听问题处理
  • 原文地址:https://www.cnblogs.com/0B0S/p/11979341.html
Copyright © 2011-2022 走看看