0

i have below function to load and dump yaml

from ruamel.yaml import YAML
import logging
import os

logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))

# YAML settings
yaml = YAML(typ="rt")
yaml.default_flow_style = False
yaml.explicit_start = False

def load_file(file):
    with open(file, "r") as f:
        return yaml.load(f)


def dump_file(data, file):
    with open(file, "w") as f:
        yaml.dump(data, f)

i am reading below yaml file using load function

hagg:
  finalVersion: '17.1X8'
  majorVersion: 17
  imageName: 'file-17.1X8-secure-signed.tgz'

i have a script to read the yaml file and update the version and save it after saving i am seeing the single quotes are gone for string

file_content = load_file(f"requirements.yaml")
file_content['hagg']['majorVersion'] = new_version

dump_file(file_content, "Updated_requirements_file.yaml")

output:

hagg:
  finalVersion: 17.1X8
  majorVersion: 17
  imageName: file-17.1X8-secure-signed.tgz

Can someone please advise on how to have quotes for string in output after dump

senthil
  • 85
  • 8

0 Answers0