YAML loader and dump for PyYAML allowing to keep keys order.
Project description
This module provide a loader and a dumper for PyYAML allowing to keep items order when loading a file (by putting them in OrderedDict) and to manage OrderedDict objects when dumping to a file.
The loader is based on stackoverflow topic (thanks to Eric Naeseth): http://stackoverflow.com/questions/5121931/in-python-how-can-you-load-yaml-mappings-as-ordereddicts#answer-5121963
Self promotion: I use it a lot with clg which allows to generate command-line definition from a configuration file for keeping order of subcommands, options and arguments in the help.
To install it
$ pip install yamlordereddictloader
To use the Loader
import yaml
import yamlordereddictloader
data = yaml.load(open('myfile.yml'), Loader=yamlordereddictloader.Loader)
To use the Dumper
import yaml
import yamlordereddictloader
from collections import OrderedDict
data = OrderedDict([
('key1', 'val1'),
('key2', OrderedDict([('key21', 'val21'), ('key22', 'val22')]))
])
yaml.dump(
data,
open('myfile.yml', 'w'),
Dumper=yamlordereddictloader.Dumper,
default_flow_style=False)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for yamlordereddictloader-0.2.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9153e0f36f2bf6e3d701fbda50d5100e887785a1db6c446b5bd1320ce9eb47f |
|
MD5 | c9c769af213c378544b5a73d89633677 |
|
BLAKE2b-256 | d75b33a61cc85d603f572e611b0318f15180542c76e3f8ecd06f652a60b7a021 |