Configuration via SimpleNamespace

Using a types.SimpleNamespace object allows us to simply add attributes as needed; this is similar to using a class definition. When defining a class, all of the assignment statements are localized to the class. When creating a SimpleNamespace object, we'll need to explicitly qualify every name with the NameSpace object that we're populating. Ideally, we can create SimpleNamespace like the following code:

>>> import types 
>>> config = types.SimpleNamespace(  
...     param1="some value", 
...     param2=3.14, 
... ) 
>>> config 
namespace(param1='some value', param2=3.14) 

This works delightfully well if all of the configuration values are independent of each other. In our case, however, we have some complex dependencies ...

Get Mastering Object-Oriented Python - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.