Reading config parameters#

Besides the input data sets for computational analysis, most coding projects rely on some form of configuration parameters. These range from booleans to toggle certain flags (like debug logging), over paths and file names to access data, to miscellaneous variables to tune the algorithm.

It’s best practice not to directly insert “magic” values deep inside your code, but rather declare them as constant variables early on, to that others can easily spot what assumptions have been made and how to adjust the parameters.

Especially the tunable parameters that will often be modified, should be moved outside of the computational code. This not only facilitates parallel execution of simulation runs with varying parameters, but also allows to easily bundle the files with input parameters with the generated output files for better reproducibility.

In addition to reading the config parameters from files in your preferred format (as explained in the previous section), you may want to directly parse some as command-line arguments for fast access. Alternatively, we will explain how to encapsulate your configuration in a Python module for highest flexibility.

Warning

Always treat sensitive data (credentials, API tokens, etc) with extra care. Try to read these variables from a separate file, which you exclude from your version control.

Index#