Exemplo n.º 1
0
def load_yaml_from_filepath(filepath: t.Union[str, 'pathlib.Path'],
                            master: CustomYamlLoader = None) -> t.Any:
    """
    See: `load_yaml` function. This function differs only with that it expects filepath
    as an argument.
    """
    contents = read_from_file(filepath)
    return load_yaml(contents, master=master)
Exemplo n.º 2
0
Arquivo: files.py Projeto: lhaze/bga
def load_data(file_name: str, encoding: str = "utf-8", errors: str = "replace") -> str:
    data_dirs = get_data_dirs()
    for data_dir in data_dirs:
        try:
            return read_from_file(data_dir / file_name, encoding=encoding, errors=errors)
        except OSError:
            pass
    raise ValueError(f"File '{file_name}' not found in {[str(d) for d in data_dirs]}")
Exemplo n.º 3
0
def load_json_from_filepath(filepath: t.Union[str, 'pathlib.Path']) -> dict:
    contents = read_from_file(filepath)
    return json.loads(contents)