I'm having difficulty modifying a saved YAML file. I want to load it, add a property to the dict, and re-save it. This is what I've done... (Python 3.9.7)
# my_file.yaml
- id: 001
name: Steve
likes:
- soccer
- steak
- id: 002
name: Mary
likes:
- tennis
- ice cream
from ruamel.yaml import YAML
with open("my_file.yaml") as file:
yaml = YAML()
l = yaml.load(file)
l[0]["address"] = "123 Street"
with open("my_file_new.yaml", 'w') as f:
yaml.dump(l, f)
output too long to include, but it is definitely not what I expected.
How do I get the original file with just one extra row added?