Modify ↓
Ticket #184 (closed defect: invalid)
Invalid sequence handling
| Reported by: | nick.demyanchuk@… | Owned by: | xi |
|---|---|---|---|
| Priority: | normal | Component: | pyyaml |
| Severity: | normal | Keywords: | |
| Cc: |
Description
Pyyaml improperly dumps sequence block. For example:
>>> from yaml import load, dump
>>> cfg = """key:
- value
- another one
- foo
"""
>>> yaml_dict = load(cfg)
>>> print yaml_dict
{'key': ['value', 'another one', 'foo']}
>>> new_cfg = dump(yaml_dict)
>>> print new_cfg
key: [value, another one, foo]
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

This is how it should be. What is your expectation ? You can check your document here: http://instantyaml.appspot.com/
%YAML 1.1 --- !!map { ? !!str "key" : !!seq [ !!str "value", !!str "another one", !!str "foo", ], } ...Do you mean you expect the flow style ?
From the documentation (http://pyyaml.org/wiki/PyYAMLDocumentation#FrequentlyAskedQuestions):
By default, PyYAML chooses the style of a collection depending on whether it has nested collections. If a collection has nested collections, it will be assigned the block style. Otherwise it will have the flow style.
If you want collections to be always serialized in the block style, set the parameter default_flow_style of dump() to False.