Spaces:
Sleeping
Sleeping
File size: 624 Bytes
7d6d833 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
import yaml
def read_yaml(file_path):
"""
Reads a YAML file and returns its contents as a Python object.
Args:
file_path (str): The path to the YAML file.
Returns:
dict or list: The parsed YAML structure (dictionary or list).
"""
try:
with open(file_path, 'r') as file:
data = yaml.safe_load(file)
return data
except FileNotFoundError:
print(f"Error: File not found at {file_path}")
except yaml.YAMLError as e:
print(f"Error parsing YAML file: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
|