Storing the configuration in PY files
The PY file format means using Python code as the configuration file as well as the language to implement the application. We will have a configuration file that's simply a module; the configuration is written in the Python syntax. This removes the need to parse the module.
Using Python gives us a number of design considerations. We have two overall strategies to use Python as the configuration file:
- A top-level script: In this case, the configuration file is simply the top-most main program
- An exec() import: In this case, our configuration file provides parameter values that are collected into module global variables
We can design a top-level script file that looks like the following code:
from simulator import ...
Get Mastering Object-oriented Python 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.