zoukankan      html  css  js  c++  java
  • Python入门:装饰器案例2

    import time

    def timer(func):  #timer(test1)  func=test1

      def deco(*args,**kwargs):

        star_time=time.time()

        func(*args,**kwargs) # run test1

        stop_time=time.time()

        print("the func run time is %s" %(stop_time-star_time))

        return deco

    @timer  # test1=timer(test1)

    def test1():

      time.sleep(3)

      print("in the test1")

    @timer  # test2=timer(test2) =deco  test2(name)=deco(name)

    def test2(name,age):

      print("test2:",name,age)

    test1()

    test2("LiMei",23)

  • 相关阅读:
    .net core
    asp.net core之abp框架
    C#
    c#
    C#
    C#
    C#
    技术术语
    mysql
    006.内测.情景之迷你财务记账
  • 原文地址:https://www.cnblogs.com/luckerzhang/p/9295440.html
Copyright © 2011-2022 走看看