K
K
Kekatoz2021-02-16 15:36:10
YAML
Kekatoz, 2021-02-16 15:36:10

How to output beautiful YAML?

there is a YAML file with content:

games:
- id: 1
name: Ships in the ocean
date: 2018-02-12
- id: 5
name: ZOO Railroad
date: 2018-03-30
- id: 14
name: Octopus-destroyer
date : 2018-03-18

how to make it output exactly the same as written in the file itself?
yaml.load outputs as a dictionary
{'games': [{'id': 1, 'name': 'Ships in the ocean', 'date': datetime.date(2018, 2, 12)}, {'id ': 5, 'name': 'ZOO Railroad', 'date': datetime.date(2018, 3, 30)}, {'id': 14, 'name': 'Octopus-destroyer', 'date': datetime.date(2018, 3, 18)}]}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2021-02-16
@Kekatoz

When outputting to the console, you need to reformat it back to yaml, or not parse it at all :)
YAML is a format intended for writing by a person. After parsing, it turns into exactly what you wrote.

D
Dr. Bacon, 2021-02-16
@bacon

ok google, "YAP yaml pretty print"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question