-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
32 lines (23 loc) · 873 Bytes
/
util.py
File metadata and controls
32 lines (23 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
""" Module for storing utility functions. """
# standard imports
from pathlib import Path
import json
from typing import Optional, Dict
def read_file(file_path: Path) -> Optional[Dict]:
"""Reads from file."""
if file_path.suffix == ".json":
with open(file_path, "r", encoding="utf-8") as file_pointer:
json_content = json.load(file_pointer)
return json_content
raise NotImplementedError(
f"Reading file of type {file_path.suffix} is not implemented."
)
def write_file(data: Dict, file_path: Path) -> None:
"""Writed to file."""
if file_path.suffix == ".json":
with open(file_path, "w", encoding="utf-8") as file_pointer:
json.dump(data, file_pointer, indent=4)
return
raise NotImplementedError(
f"Writing file of type {file_path.suffix} is not implemented."
)