Read Data from YAML File using Python

test.yaml

parameters:
  host: localhost
  port: 8080
  user: root

PyYAML library

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

with open('test.yaml', mode='r') as file:
    data = yaml.load(file, Loader=yaml.FullLoader)

    print(data)

Leave a Comment

Cancel reply

Your email address will not be published.