Skip to content

Commit 33fb5f5

Browse files
committed
Refactor file_reader.py
1 parent 1f9f9ad commit 33fb5f5

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

utils/file_reader.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import json
22
from pathlib import Path
33

4-
BASE_PATH = Path.cwd().joinpath("data")
4+
BASE_PATH = Path.cwd() / "data"
55

66

7-
def read_file(file_name):
7+
def read_file(file_name: str) -> dict:
88
file_path = get_file_with_json_ext(file_name)
99
with open(file_path, mode="r", encoding="utf-8") as f:
1010
return json.load(f)
1111

1212

13-
def get_file_with_json_ext(file_name):
14-
return (
15-
BASE_PATH.joinpath(file_name)
16-
if ".json" in file_name
17-
else BASE_PATH.joinpath(f"{file_name}.json")
18-
)
13+
def get_file_with_json_ext(file_name: str) -> Path:
14+
if not file_name.endswith(".json"):
15+
file_name += ".json"
16+
return BASE_PATH / file_name

0 commit comments

Comments
 (0)