相关疑难解决方法(0)

检查函数是否被调用为装饰器

在下面的最小例子decorate中调用了两次.首先使用@decorate,第二个是正常的函数调用decorate(bar).

def decorate(func):
    print(func.__name__)
    return func

@decorate
def bar():
    pass

decorate(bar)
Run Code Online (Sandbox Code Playgroud)

是否可以decorate通过使用@decorate或作为普通函数调用来查看调用是否被调用?

python decorator python-3.x python-decorators

6
推荐指数
1
解决办法
442
查看次数

标签 统计

decorator ×1

python ×1

python-3.x ×1

python-decorators ×1