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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.