from functools import wraps
def test(func):
@wraps(func)
def inner_func():
inner_obj = 'inner_obj'
print(inner_obj)
return func()
return inner_func
@test
def test_func():
return False
a = test_func()
print(a)
我想在test_func中获取装饰器的inner_obj变量,能实现吗??请问
当然可以了。
你可以给 test_func 加一个参数嘛。在 inner_func 中调用 test_func 的时候把参数传过去