Answer the question
In order to leave comments, you need to log in
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
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question