示例#1
0
def read_file(path_or_stream: os.PathLike, mode: str = "r") -> str:
    """Read a file."""
    if isinstance(path_or_stream, (str, os.PathLike)):
        with open_file(path_or_stream, mode) as buff:
            data = buff.read()
        return data
    if is_readable(path_or_stream):
        return path_or_stream.read()

    raise OSError(f"Could not read {path_or_stream}")
示例#2
0
def read_file(f: PathLike) -> str:
    with open(f, "r") as f:
        return f.read()