Interview Prep/Python for DevOps/Runtime, file, subprocess & encoding errors

A YAML value `country: NO` is loaded as `False`, and version `1.10` becomes `1.1`.

IntermediateTroubleshootingRuntime, file, subprocess & encoding errors
Answer

Likely causes → PyYAML implements YAML 1.1, where yes/no/on/off (any case) are booleans, and unquoted numbers are parsed as floats.

Diagnose →

yaml.safe_load("a: NO\nb: 1.10\nc: 010")   # {'a': False, 'b': 1.1, 'c': 8}

Fix → Quote strings in the YAML ("NO", "1.10"), or use ruamel.yaml (YAML 1.2 by default, where NO is a string) for files you do not control.

Prevent → Lint YAML with yamllint (truthy rule) and quote version strings.

All Python for DevOps questions Roadmap: Python for automation

More on Runtime, file, subprocess & encoding errors