[Python] How to keep !!timestamps and other tags when using ruamel.yaml

Discussão em 'Python' iniciado por Stack, Maio 5, 2025.

  1. Stack

    Stack Membro Participativo

    I currently work on a small automation script in Python to add specific lines to a YAML file. The script is working for now, but the created modified file is ignoring a couple of tags that are necessary in the file:

    I have this small part that keeps changing. The original:

    example:
    - x: ~
    y: !!timestamp 2025-05-04


    The edited:

    example:
    - x:
    y: 2025-05-04


    I don't know how to adjust this. I know it's Python interpreting the ~ as None and the timestamp as a date format. Is there a workaround? Since the stuff I need to edit is in an entirely different group I thought about finding a solution that involves only loading the group I need to edit.

    Continue reading...

Compartilhe esta Página