files.py 373 Bytes
Newer Older
Matteo's avatar
Matteo committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import json
import yaml


def get_file_content(file_name: str, format: str) -> dict:

    with open(file_name) as fd:
        if format == "yaml":
            content = yaml.safe_load(fd)
            return content
        elif format == "json":
            content = json.load(fd)
        else:
            raise ValueError("Format not supported")

        return content