I want to print "getting x attr" whenever I use the dot notation to get an attribute.
For example
class MyClass:
my_attribute = "abc"
print(MyClass.my_attribute)
I'd expect it to output like this:
>>> getting my_attribute attr
>>> abc
I'm not instantiating the class.
I tried to add a print statement to MyClass.__getattr__()
and MyClass.__getattribute__()
but none of these will display anything.
I tried the following:
class MyClass:
def __getattr__(self, key):
print("running __getattr__")
return super().__getattr__(key)
def __getattribute__(self, __name: str) -> Any:
print("running __getattribute__")
return super().__getattribute__(__name)
my_attribute = "abc"