June 2019
Beginner to intermediate
770 pages
19h 24m
English
We'll use a three-stage process to incorporate environment variables. For this application, the environment variables will be used to override configuration file settings. The first stage is to gather the default values from the various files. This is based on the examples shown in Chapter 14, Configuration Files and Persistence. We can use code like the following:
config_locations = ( Path.cwd(), Path.home(), Path.cwd() / "opt", # A testing stand-in for Path("/opt") Path(__file__) / "config", # Other common places... # Path("~someapp").expanduser(),)candidate_paths = (dir / "ch18app.yaml" for dir in config_locations)config_paths = (path for path in candidate_paths if path.exists()) ...
Read now
Unlock full access