pyyaml

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

pyyaml looks like is outdated

pyyaml looks like is outdated Question: As I searched for pypi, more specifically at this address: pyyaml docs I noticed that the pyaml package, previously quite used, is no longer receiving updates. I was thinking of using it for a project, but if that’s really it, it makes more sense to look for other alternatives. …

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

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

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

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

Python opening/loading yaml file changes values (numbers ?) if they contain a colon : and less than 3 digits after the colon

Python opening/loading yaml file changes values (numbers ?) if they contain a colon : and less than 3 digits after the colon Question: Simple example.yml file Base: StartTime: 645:0 EndTimes: 645:023 MidTimes: 645:02 mac: 99:19:b9:fa:37:99 MissionStartTimestamp: -2037:14522 MissionEndTimestamp: -2037:14522 When it is loaded into python import yaml with open("example.yml", ‘r’) as file: example_ = yaml.safe_load(file) …

Total answers: 2

Python Console cannot find associated class when loading from yaml file

Python Console cannot find associated class when loading from yaml file Question: I would like to save an instance of a class in a YAML File (to make it more human readable). Consider this example code: import tempfile from pathlib import Path import yaml class MyClass: def __init__(self, attribute): self.attribute = attribute if __name__==’__main__’: my_instance …

Total answers: 1

`pyyaml` can't parse `pydantic` object if `typing` module is used

`pyyaml` can't parse `pydantic` object if `typing` module is used Question: Let me start off by saying I wanted to open an issue in pydantic repo. Once I started rubber duck debugging I came up to the conclusion it’s actually pyyaml that isn’t working right but I’m not so sure anymore. from dataclasses import dataclass …

Total answers: 2