multi-document

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

Write multiple JSON lines to JSON file

Write multiple JSON lines to JSON file Question: I have a code that needs to read a JSON file with multiple lines, i.e: {"c1-line1": "value", "c2-line1": "value"} {"c1-line2": "value", "c2-line2": "value"}… and, after change the keys values (already working), I need to write a new json file with these multiple lines, i.e: {"newc1-line1": "value", "newc2-line1": …

Total answers: 1

How do I read/write markdown yaml frontmatter with ruamel.yaml?

How do I read/write markdown yaml frontmatter with ruamel.yaml? Question: I want to use Python to read and write YAML frontmatter in markdown files. I have come across the ruamel.yaml package but am having trouble understanding how to use it for this purpose. If I have a markdown file: — car: make: Toyota model: Camry …

Total answers: 1

Format JSON to one line per input

Format JSON to one line per input Question: I’m trying to make my json compatible with Google ML, which after some searching means having one line per input instance (Input instances are not in JSON format.) How can I change my code to have only one line per instance? (img variable is the image I …

Total answers: 1

How to parse a YAML file with multiple documents?

How to parse a YAML file with multiple documents? Question: Here is my parsing code: import yaml def yaml_as_python(val): “””Convert YAML to dict””” try: return yaml.load_all(val) except yaml.YAMLError as exc: return exc with open(‘circuits-small.yaml’,’r’) as input_file: results = yaml_as_python(input_file) print results for value in results: print value Here is a sample of the file: ingests: …

Total answers: 2