Python Forum
what if __getattr__() can't find an attribute, either? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: what if __getattr__() can't find an attribute, either? (/thread-35200.html)



what if __getattr__() can't find an attribute, either? - Skaperen - Oct-08-2021

what if __getattr__() can't find an attribute, either? what should it do? return None?


RE: what if __getattr__() can't find an attribute, either? - Yoriz - Oct-08-2021

https://docs.python.org/3/reference/datamodel.html#object.__getattr__ Wrote:object.__getattr__(self, name)
Called when the default attribute access fails with an AttributeError (either __getattribute__() raises an AttributeError because name is not an instance attribute or an attribute in the class tree for self; or __get__() of a name property raises AttributeError). This method should either return the (computed) attribute value or raise an AttributeError exception.