yaml

Python, after save yaml file the formatting of a list elements is not proper

Python, after save yaml file the formatting of a list elements is not proper Question: I’m new to Python so maybe my problem is trivial but I don’t know how to solve it. I need to prepare a small script to modify yaml files. The problem I’ve faced is that after saving the file the …

Total answers: 1

Python Yaml: Iterating through text values

Python Yaml: Iterating through text values Question: I have this docker-compose.yaml file. I want to iterate through parameters that can be customized by a user. Meaning that I’m only interested in Values, specifically text values. Examples of such values would be: debug,disable-ssl-client-postgres found under the services: callback: environment: SPRING_PROFILES_ACTIVE: key ./ found under the services: …

Total answers: 2

Resolving internal variables in YAML file

Resolving internal variables in YAML file Question: I have a YAML file which uses keys as references/variables in different sections as in the following example. download: input_data_dir: ./data/input prepare: input_dir: ${download.input_data_dir} output_dir: ./data/prepared process: version: 1 output_dir: ./output/${process.version} I tried loading the YAML file in Python params = yaml.safe_load(open("../params.yaml")). This outputs ${download.input_data_dir} for params[‘prepare’][‘input_dir’], while …

Total answers: 2

Combining Dumper class with string representer to get exact required YAML output

Combining Dumper class with string representer to get exact required YAML output Question: I’m using PyYAML 6.0 with Python 3.9. In order, I am trying to… Create a YAML list Embed this list as a multi-line string in another YAML object Replace this YAML object in an existing document Write the document back, in a …

Total answers: 1

Preserving long single line string as is when round-triping in ruamel

Preserving long single line string as is when round-triping in ruamel Question: In the below code, I’m trying to write a load and write a YAML string back to ensure that it retains the spacing as is. import ruamel.yaml yaml_str = """ long_single_line_text: Hello, there. This is nothing but a long single line text which …

Total answers: 1

writing Yaml file in python with no new line

writing Yaml file in python with no new line Question: Let’s say I have the following snippet : import yaml Key = ["STAGE0", "STAGE1"] dict = {} dict[Key[0]] = [‘ ‘] dict[Key[1]] = [‘ ‘] dict[Key[0]][0]="HEY" dict[Key[0]][0]="WHY newline?" with open("SUMMARY.YAML", "w") as file_yaml: yaml.dump(dict, file_yaml) The output SUMMARY.YAML file looks like this : STAGE0: – …

Total answers: 2

Can't correctly dump Ansible vault into yaml with Python

Can't correctly dump Ansible vault into yaml with Python Question: I have a python dictionary with an Ansible vault as a value. I can’t seem to be able to correctly dump it into a yaml output with the correct formatting. I’m using the ansible-vault package to generate the encrypted data as follows: from ansible_vault import …

Total answers: 1

python iterate yaml and filter result

python iterate yaml and filter result Question: I have this yaml file data: – name: acme_aws1 source: aws path: acme/acme_aws1.zip – name: acme_gke1 source: gke path: acme/acme_gke1.zip – name: acme_oci source: oci path: acme/acme_oci1.zip – name: acme_aws2 source: aws path: acme/acme_aws2.zip – name: acme_gke2 source: gke path: acme/acme_gke2.zip – name: acme_oci2 source: oci path: acme/acme_oci2.zip …

Total answers: 2

Converting Python dictionary to YAML file with lists as multiline strings

Converting Python dictionary to YAML file with lists as multiline strings Question: I’m trying to convert a Python dictionary of the following form: { "version": "3.1", "nlu": [ { "intent": "greet", "examples": ["hi", "hello", "howdy"] }, { "intent": "goodbye", "examples": ["goodbye", "bye", "see you later"] } ] } to a YAML file of the following …

Total answers: 2

Python: nested dict and specification in one key

Python: nested dict and specification in one key Question: I need to make a yaml file with a dict and a specific format. The desired format of the yaml file would be: classification: – type: 4 probability: 1.0 So far I created a dict with the following: dic = { ‘classification’: { ‘type’: 4, ‘probability’: …

Total answers: 1