Write Data to YAML File using Python

PyYAML library

  1. Install PyYAML library from the command line:
pip install PyYAML
  1. Write data to YAML file:
import yaml

data = {
    'parameters': {
        'host': 'localhost',
        'port': 8080,
        'user': 'root',
    }
}

with open('test.yaml', mode='w') as file:
    yaml.dump(data, file, indent=2)

Leave a Comment

Cancel reply

Your email address will not be published.