yaml

How to convert string to valid json or yaml

How to convert string to valid json or yaml Question: I have a large script that parses js with a dataframe entry, but to shorten the question, I put what I need in a separate variable. My variable contains the following value value = "{from:[3,4],to:[7,4],color:2},{from:[3,6],to:[10,6],color:3}" I apply the following script and get data like this …

Total answers: 2

How can I maintain formatting while updating a yaml file using ruamel?

How can I maintain formatting while updating a yaml file using ruamel? Question: I have a multi-document YAML file. I am interested in modifying the third document only (this modification will be later made using other code and conditions). After some research, I selected ruamel since it was reported to preserve order and format. My …

Total answers: 1

build new variables in Jinja2 Loop and use it

build new variables in Jinja2 Loop and use it Question: I have a file containing a YAML document, with informations about vlans: #yaml_file.yaml – vlan: 123 name: DATEN-VLAN – vlan: 124 name: PRINTER-VLAN – vlan: 125 name: WLAN-VLAN Then I created a Jinja2Template to loop through the vlans: {% for vlan in vlans %} interface …

Total answers: 1

python import yaml – but which one?

python import yaml – but which one? Question: Ok, so you clone a repo, there’s an import import yaml ok, so you do pip install yaml and you get: ERROR: No matching distribution found for yaml Ok, so you look for a package with yaml in it, and there’s like a gazillion of them… usually …

Total answers: 5

Pyyaml dump does not produce anchors for the same objects

Pyyaml dump does not produce anchors for the same objects Question: I was experimenting a bit with PyYaml and I wanted to have a reference to a value appearing previously in the yaml. To give an example: import yaml a=25 dict_to_dump={‘a’:a,’b’:a} yaml.dump(dict_to_dump) from what I understood from the specifications pyyaml should be adding an anchor …

Total answers: 2

Combining dictionaries with a particular key: Python

Combining dictionaries with a particular key: Python Question: I have the following dictionaries generated using for loop and I would to combine and dump them into one YAML file. dict1 {‘name’: ‘test’, ‘version’: ‘0011 * *? *’, ‘datasets’: [{ ‘dataset’: ‘dataset_a’, ‘match_on’: [‘code’], ‘columns’: {‘include’: [‘aa’, ‘bb’, ‘cc’]}}] } dict2 {‘name’: ‘test’, ‘version’: ‘0011 * …

Total answers: 1

how to read specific lines of list in yaml to python

how to read specific lines of list in yaml to python Question: I have 2 files, first is ip_list.yaml which is globals: hosted_zone: "test.com" endpoint_prefix: defalt ip_v4: – 123 – 234 – 456 ip_v6: – 123 – 234 – 345 and the other one is network.py # Creating IP rules sets ip_set_v4 = wafv2.CfnIPSet( self, …

Total answers: 1

How to edit a file with multiple YAML documents in Python

How to edit a file with multiple YAML documents in Python Question: I have the following YAML file: apiVersion: apps/v1 kind: Deployment metadata: name: nodejs namespace: test labels: app: hello-world spec: selector: matchLabels: app: hello-world replicas: 100 template: metadata: labels: app: hello-world spec: containers: – name: hello-world image: test/first:latest ports: – containerPort: 80 resources: limits: …

Total answers: 2

Get specific data from dictionary generated from yaml

Get specific data from dictionary generated from yaml Question: I have a yaml that I need to process with a python script, the yaml is something like this: user: john description: Blablabla version: 1 data: data1: {type : bool, default: 0, flag: True} data2: {type : bool, default: 0, flag: True} data3: {type : float, …

Total answers: 2

How do I generate yaml file via python code?

How do I generate yaml file via python code? Question: I need to generate a yaml file and want to use python to do that. This (How can I write data in YAML format in a file?) helped me a lot but I am missing a few more steps. I want to have something like …

Total answers: 2