Aleksey Tsalolikhin
Aleksey Tsalolikhin

Reputation: 1668

ruamel.yaml dump contains "..."

I need to sort the contents of a YAML file, and I'm learning ruamel.yaml to do this.

Given this file example.yml:

---
- job:
    name: this is the job name

And this Python program:

import sys
import ruamel.yaml

yaml = ruamel.yaml.YAML()  # defaults to round-trip

# Read YAML file
with open('example.yml', 'r') as f:
    data = yaml.load(f)

yaml.dump(data[0]['job']['name'], sys.stdout)

I get the job name, but I also get an extra line with ...:

$ python example.py
this is the job name
...
$

I wasn't expecting to see the ... so I'm a tad confused. Where is it coming from and why?

Upvotes: 0

Views: 193

Answers (1)

tripleee
tripleee

Reputation: 189307

It's a YAML boundary marker.

It's not entirely clear what exactly you are hoping to produce here. If you don't specifically want a YAML document on output, probably just print the thing. I'm guessing you are in the middle of debugging something, because this seems unrelated to the actual task you claim to be working on.

If you want to sort the YAML file internally, the PyYAML module does that by default. If you need it for Ruamel specifically, ruamel.yaml equivalent of sort_keys? has a solution.

Upvotes: 2

Related Questions