带参数的装饰器

import time
def loop(delay=1):
    def middle(func):
        def inner(self, *args, **kwargs):
            time.sleep(delay)
            return  func(self, *args, **kwargs)
        return inner
    return middle

class A():
    @loop(delay=3)
    def a(self,num):
        print(num)

A().a(5)

  

posted @ 2020-03-16 23:40  Andrew.SH  阅读(133)  评论(0编辑  收藏  举报