The ChainMap use case
The use case for chaining maps together fits nicely with Python's concept of local versus global definitions. When we use a variable in Python, first the local namespaces and then the global namespaces are searched, in that order. In addition to searching both namespaces for a variable, setting a variable is done in the local namespace without disturbing the global namespace. This default behavior (without the global or nonlocal statements) is also how ChainMap works.
When our applications start running, we often have properties that come from command-line parameters, configuration files, OS environment variables, and possibly a default file of settings installed with the software. These have a clear precedence order ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access