pip install pyyaml
python
import yaml
python
with open('file.yaml', 'r') as file:
data = yaml.load(file, Loader=yaml.FullLoader)
yaml
person:
name: John Doe
age: 30
address:
city: New York
state: NY
python
yaml
users:
- name: John Doe
age: 30
address:
city: New York
state: NY
- name: Jane Smith
age: 25
address:
city: Los Angeles
state: CA
python
for user in data['users']:
print("Name:", user['name'])
print("City:", user['address']['city'])
print("State:", user['address']['state'])
print()