I want to change __getattr__during class instance creation. For instance:
class AttrTest(object):
def __init__(self):
self.__getattr__ = self._getattr
def _getattr(self, attr):
print("Getting {}".format(attr))
I would expect it to look like this:
class AttrTest(object):
def __getattr__(self, attr):
print("Getting {}".format(attr))
But this is not so.
For example, when I run:
>>> at = AttrTest()
>>> at.test
I would expect both classes to print Getting test, but the upper class chose AttributeError.
Can it __getattr__not change in this way?
source
share