Re: dump different scalar styles in the same document in PyYAML

Ingy dot Net <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <[email protected]>
This works for me:

from yaml import *;

tokens = (
    StreamStartEvent(),
    DocumentStartEvent(explicit=True),
    MappingStartEvent(anchor=None, tag=None, implicit=True),
    ScalarEvent(None, None, [1,1], 'value1', style=''),
    ScalarEvent(None, None, [1,1], '1', style=''),
    ScalarEvent(None, None, [1,1], 'value2', style=''),
    ScalarEvent(None, None, [1,1], 'line1\nline2\nline3', style='|'),
    MappingEndEvent(),
    DocumentEndEvent(),
    StreamEndEvent(),
)

print emit(tokens)

- Ingy

On Mon, Apr 6, 2009 at 2:59 PM, Andrey Somov <[email protected]> wrote:

> Hi All,
> even though there is plenty of options while dumping YAML in PyYAML, I
> could not find how I can mix different scalar styles in the same
> document.
> For instance, instead of:
> ---
> value1: 1
> value2: 'line1
>
>     line2
>
>    line3'
> ...
> I would like to dump
> ---
> value1: 1
> value2: |-
>     line1
>     line2
>     line3
> ...
>
> So I would like to use the plain scalar style but if the value
> contains '\n' then the literal style shall be used.
> Is it possible?
>
> Andrey
>
>
> ------------------------------------------------------------------------------
> _______________________________________________
> Yaml-core mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/yaml-core
>

------------------------------------------------------------------------------

_______________________________________________
Yaml-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/yaml-core
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.