装饰器

Posted by tzwlwy's Blog on August 25, 2020

第三次看装饰器了!!!!

def newdecorator(i):
    def decorator(func):
        def restructure(x):
            func(x)
            print('this is decorator %s%s'%(i,x))
        return restructure
    return decorator

@newdecorator('?')
def target(x):
    print('this is target %s'%x)

target('!')

target(x) == newdecorator(i)(target)(x) == decorator(target)(x) == reconstructure(x)