April 2018
Intermediate to advanced
374 pages
8h 35m
English
Within Python, you can view environment variables using os.environ, for example:
import osos.environ.get('CONFIG_FILE’)
You can set a default value when using os.environ.get in your code to handle a case when the environment variable isn’t set:
import osos.environ.get('CONFIG_FILE’,’./feature.flags’)
We set the CONFIG_FILE environment variable here to show you how it could be done, but it is not strictly necessary to read the configuration file–more a convenience to allow you to override that value if desired.
Python also includes a module to parse and read INI-style configuration files, like the one we added in ConfigMap. Continuing with the example:
from configparser import SafeConfigParserfrom pathlib ...
Read now
Unlock full access