Discuss / Python / 简单写一下

简单写一下

Topic source

金钟铉

#1 Created at ... [Delete] [Delete and Lock User]
import functools
def log(func):
    if not isinstance(func,(int,float,str)) :
        @functools.wraps(func)
        def A():
            print('d')
            return func()
        return A
    else:
        def B(func1):
            @functools.wraps(func1)
            def C():
                print('d',func)
                return func1()
            return C
        return B
@log
def a():
    print('b')
    return 'c'
print(a())
print(a.__name__)

想问一下  可不可以让装饰器添加的功能在原函数执行后再执行,目前我看到的都是先执行装饰器里的功能诶

金钟铉

#3 Created at ... [Delete] [Delete and Lock User]

原函数不要跟return不就好了


  • 1

Reply