Modify

Ticket #184 (closed defect: invalid)

Opened 3 years ago

Last modified 3 years ago

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

comment:1 follow-up: ↓ 2 Changed 3 years ago by anonymous

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.

comment:2 in reply to: ↑ 1 Changed 3 years ago by anonymous

Thank you! default_flow_style works excellent.

comment:3 Changed 3 years ago by xi

  • Status changed from new to closed
  • Resolution set to invalid
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.