DzmitrySha/python-project-lvl2

View on GitHub
gendiff/parser.py

Summary

Maintainability
A
0 mins
Test Coverage
B
87%
"""Parser module"""

import json
import yaml


def parse(data, format_name):
    if format_name == '.json':
        return json.load(open(data))
    if format_name in ('.yml', '.yaml'):
        return yaml.safe_load(open(data))

    raise ValueError('Unknown file format')