Source code for smif.data_layer.load
# -*- coding: utf-8 -*-
"""Parse yaml config files, to construct sector models
"""
import yaml
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
[docs]def load(file_path):
"""Parse yaml config file into plain data (lists, dicts and simple values)
Parameters
----------
file_path : str
The path of the configuration file to parse
"""
with open(file_path, 'r') as file_handle:
return yaml.load(file_handle, Loader=Loader)
[docs]def dump(data, file_path):
"""Write plain data to a file as yaml
Parameters
----------
file_path : str
The path of the configuration file to write
data
Data to write (should be lists, dicts and simple values)
"""
with open(file_path, 'w') as file_handle:
return yaml.dump(data, file_handle, Dumper=Dumper,
default_flow_style=False)