[Python] preserve backslash of multiple line string when using ruamel-yaml

Discussão em 'Python' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    In newest version of ruamel-yaml 0.18.10 . If i want to preserve backslash of multiple line string. How should i do.

    I use code like below.

    import pathlib
    from ruamel.yaml import YAML

    control_file = 'xx/nist_ocp4.yml'

    yaml = YAML()
    yaml.preserve_quotes = True
    d = yaml.load(pathlib.Path(control_file))
    yaml.dump(d, pathlib.Path(control_file))


    Before running code:

    controls:
    - id: AC-1
    status: not applicable
    description: "The organization:\n a. Develops, documents, and disseminates to [Assignment:\
    \ or whenever a significant change occurs]"


    After running code:

    controls:
    - id: AC-1
    status: not applicable
    description: "The organization:\n a. Develops, documents, and disseminates to [Assignment:
    or whenever a significant change occurs]"

    Continue reading...

Compartilhe esta Página