I'm a Python newbie with a very particular itch to experiment with Python's dot-name-lookup process. How do I code either a class or function in "make.py" so that these assignment statements work succesfully?
import make
make.a.dot.separated.name = 666
make.something.else.up = 123
make.anything.i.want = 777
The special
__getattr__
method is called when a named value isn't found. The linemake.anything.i.want
ends up doing the equivalent of:The above implementation uses these calls to
__getattr__
to create a chain ofMake
objects each time an unknown property is accessed. This allows the dot accesses to be nested arbitrarily deep until the final assignment at which point a real value is assigned.Python documentation - customizing attribute access: