Using class-as-namespace for configuration
Python offers a variety of ways to package application inputs and configuration files. We'll continue to look at writing files in Python notation because it's elegant and the familiar syntax can lead to easy-to-read configuration files.
A number of projects allow us to use a class definition to provide configuration parameters. The use of a class hierarchy means that inheritance techniques can be used to simplify the organization of parameters. The Flask
package, in particular, can do this. We looked at Flask in the Using the Flask framework for RESTful APIs recipe, and a number of related recipes.
In this recipe, we'll look at how we can represent configuration details in Python class notation.
Getting ready
Python notation for defining the attributes of a class can be simple, easy to read, and reasonably flexible. We can, with a little work, define a sophisticated configuration language that allows someone...