I have a class as follows:
class A:
def __init__(self, x, y):
self.x = x
self.y = y
def __call__(self, func):
def wrapper():
print("decorated", self.x, self.y)
func()
return wrapper
Now if I want to use this class to decorate functions:
@A(4, 5)
def fn():
print("original function")
fn()
Output:
decorated 4 5
original function
Questions:
Since in
@A(3, 4)the__init__class constructor is called, where did the created instance of classAgo? Is there a way to reference it?How can I access the properties
self.x, self.youtside of the class, without callingfn()? (I want something likefn.xorfn.y, but they don't work)