[Python] add new field to yaml file using ruamel.yaml adds extras new line

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

  1. Stack

    Stack Membro Participativo

    Original file

    controls:
    - id: AC-1
    levels:
    - high
    - moderate
    - low

    - id: AC-2


    When i add a new field to mapping, it looks like this, rules is the new added field.It adds a new extra new line.

    controls:
    - id: AC-1
    levels:
    - high
    - moderate
    - low

    rules: []
    - id: AC-2


    But i want this, is this possible.

    controls:
    - id: AC-1
    levels:
    - high
    - moderate
    - low
    rules: []

    - id: AC-2


    I saw there is a similar question Modifying YAML using ruamel.yaml adds extra new lines, but i believe this is very old.

    Continue reading...

Compartilhe esta Página