Different YAML array representations

前端 未结 2 473
既然无缘
既然无缘 2021-01-13 04:03

I\'m writing a file type converter using Python and PyYAML for a project where I am translating to and from YAML files multiple times. These file are then used by a separate

2条回答
  •  一生所求
    2021-01-13 04:50

    Yes, to any YAML parser that follows the spec, they are equivalent. You can read the spec here: http://www.yaml.org/spec/1.2/spec.html

    Section 3.2.3.1 is particularly relevant (emphasis mine):

    3.2.3.1. Node Styles

    Each node is presented in some style, depending on its kind. The node style is a presentation detail and is not reflected in the serialization tree or representation graph. There are two groups of styles. Block styles use indentation to denote structure; In contrast, flow styles styles rely on explicit indicators.

    To clarify, a node is any structure in YAML, including arrays (called sequences in the spec). The single-line style is called a flow sequence (see section 7.4.1) and the multi-line style is called a block sequence (section 8.2.1). A compliant parser will deserialize both into identical objects.

提交回复
热议问题