Is it possible to access function attributes inside a decorator? Consider below piece of code.
def deco(a):
def wrap():
print(a.status)
a()
print(a.status)
return wrap
@deco
def fun1():
fun1.status="bar"
fun1.status="foo"
fun1()
I expected the output to be :
foo
bar
But I get the below error:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
fun1()
File "D:\python_projects\test_suite\func_attribute.py", line 3, in wrap
print(a.status)
AttributeError: 'function' object has no attribute 'status'
Is there any way to make this work since
def fun1():
fun1.status="bar"
fun1.status="foo"
a=fun1
print(a.status)
a()
print(a.status)
Outputs:
foo
bar
As expected.