Python Object Lookup Process

Python
Author

Imad Dabbura

Published

November 3, 2022

Whenever a variable, function, or module is invoked in Python, there is a hierarchy that determines where it looks for these objects.

It is important to note that while locals() and globals() are explicitly dictionaries and __builtin__ is technically a module object, when searching __builtin__ for a given property, we are just doing a dictionary lookup inside its locals() map (this is the case for all module objects and class objects!).

As a result of the above: