From fcf6fbdaaae460bed917b73db033a3d063443389 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Fri, 12 Feb 2021 15:49:19 +0300 Subject: Add new procedure to return a python dict from a json file * gn3/file_utils.py (jsonfile_to_dict): New procedure * tests/unit/test_file_utils.py: New test-cases. --- gn3/file_utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gn3') diff --git a/gn3/file_utils.py b/gn3/file_utils.py index 36e3b6d..79e6854 100644 --- a/gn3/file_utils.py +++ b/gn3/file_utils.py @@ -1,8 +1,10 @@ """Procedures that operate on files/ directories""" import hashlib +import json import os from functools import partial +from typing import Dict def get_dir_hash(directory: str) -> str: @@ -34,3 +36,11 @@ Otherwise return ENVIRON_VAR/ROOT_DIR/FILE_NAME. if os.path.isfile(_file): return _file raise FileNotFoundError + + +def jsonfile_to_dict(json_file: str) -> Dict: + """Give a JSON_FILE, return a python dict""" + with open(json_file) as _file: + data = json.load(_file) + return data + raise FileNotFoundError -- cgit v1.2.3