INNER CODE UNIT · Python
load_yaml
yohey-w/multi-agent-shogun · scripts/slim_yaml.py:28
def load_yaml(filepath):
"""Safely load YAML file."""
try:
with open(filepath, 'r', encoding='utf-8') as f:
return yaml.safe_load(f) or {}
except FileNotFoundError:
return {}
except yaml.YAMLError as e:
print(f"Error parsing {filepath}: {e}", file=sys.stderr)
return {}
def save_yaml(filepath, data):
"""Safely save YAML file."""
try:
with open(filepath, 'w', encoding='utf-8') as f:
yaml.dump(data, f, allow_unicode=True, sort_keys=False, default_flow_style=False)
return True