Online pyyaml Compiler

Online pyyaml Compiler and Playground.

Python
import yaml

# Example Python dictionary
data = {
    'name': 'Alice',
    'age': 30,
    'languages': ['English', 'French'],
    'details': {
        'hobbies': ['Reading', 'Hiking'],
        'active': True
    }
}

# --- Write the dictionary to a YAML file ---
with open('data.yaml', 'w') as f:
    yaml.dump(data, f)

print("Data written to data.yaml")

# --- Read the YAML file back into a Python dictionary ---
with open('data.yaml', 'r') as f:
    loaded_data = yaml.safe_load(f)

print("\nData loaded from data.yaml:")
print(loaded_data)