Tested on:RPi3; Raspbian Stretch; Python3
Prerequisites:Raspberry Pi with Raspbian Jessie and internet connection (see steps 1-7 in the Introduction)

Python 3 settings file with YAML for data serialization

Bigger projects usually require a bunch of settings. An option for managing these is the data serialization language YAML. YAML uses human-readable text files for storing and accessing data and supports all Python data types (including instances of Python classes).

Install YAML and run the demo script with

Store data
Display the generated file config.yml by entering

The parameter content is a dict holding an int and a str:

The configuration file was created with this code:

yaml.dump stores data under the given filename structured in the YAML format.

Load data
The stored parameters can be loaded into a dict with safe_load:

Additionally, SimpleNamespace can be used For a better access with Dot syntax.

Full script
Click on Full Script to show all of the code.

PyYAML Github: https://github.com/yaml/pyyaml
PyYAML docs: http://pyyaml.org/wiki/PyYAMLDocumentation
Stackoverflow SimpleNamespace: https://stackoverflow.com/questions/16279212/how-to-use-dot-notation-for-dict-in-python

Knight of Pi

Johannes Bergs aka Knight of Pi. Diploma in Bioinformatics, some Webdesign and Python coding then. Living in the beautiful city of Vienna.


Time limit is exhausted. Please reload CAPTCHA.