Python offers a variety of ways to package application inputs and configuration files. We'll look at writing files in YAML notation because it's elegant and simple.
How can we represent configuration details in YAML notation?
Python doesn't have a YAML parser built in. We'll need to add the pyyaml
project to our library using the pip
package management system. Here's how the installation looks:
MacBookPro-SLott:pyweb slott$ pip3.5 install pyyaml Collecting pyyaml Downloading PyYAML-3.11.zip (371kB) 100% |████████████████████████████████| 378kB 2.5MB/sInstalling collected packages: pyyaml Running setup.py install for pyyaml ... done Successfully installed pyyaml-3.11
The elegance of the YAML syntax is that simple indentation is used to show the structure of the document. Here's an example of some settings that we might encode in YAML:
query:
mz:
- ANZ532
- AMZ117
- AMZ080
url:
scheme: http
netloc: forecast.weather...