def decorator(*args, **kwargs):
def inner(f):
print(kwargs['here'])
return f
return inner
class Test:
def test(self, a, b):
@decorator(here='access/change this value')
def add(a, b):
print(a + b)
add(a, b)
return
if __name__ == '__main__':
t = Test()
t.test(1, 2)
How to use "t" to extract or change the value "access/change this value" from a decorator's args on a subfunction. getattribute can only help get function(self) not subfunction, am I right?
For example, I would like to get the value "access/change this value" without running function test. Or change arg here = [original str] + "a new str"