gpt4 book ai didi

python - 查找模块中的所有装饰函数

转载 作者:太空狗 更新时间:2023-10-29 21:17:57 24 4
gpt4 key购买 nike

是否可以在运行时查明函数是否被装饰?例如,我能否找到一个模块中所有由“example”修饰的函数?

@example
def test1():
print "test1"

最佳答案

既然您已经表明您可以控制包装器代码,下面是一个示例:

def example(f):
f.wrapped = True
return f

@example
def test1():
print "test1"

def test2():
print "test2"


print test1.wrapped
print hasattr(test2, 'wrapped')

关于python - 查找模块中的所有装饰函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2144109/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com