Puzzle 12: Explanation
Let’s learn how to attribute lookup works in Python.
We'll cover the following...
Let’s try it!
Try executing the code below to verify the result:
Press + to interact
class Seeker:def __getattribute__(self, name):if name not in self.__dict__:return '<not found>'return self.__dict__[name]s = Seeker()print(s.id)
Explanation
When we write s.id, Python does an attribute lookup (see Puzzle 1: Ready Player One). Python defines several hooks that bypass the usual attribute lookup algorithm. The two main ...