So this block of code tells me build_master_config_dictionary()
is not defined. I know if I declare this statement at the bottom of code it will work, but I would like to contain the list of constants at the top of the python script for readability. This script will eventually contain a bunch of similar constants that will be used by other scripts in my program.
Is there a better way of doing this?
import json
from pathlib import Path
from glob import glob
JSON_CONFIG_DIR = "data\JSON\Configs"
MASTER_CONFIG_SITE_DICT = build_master_config_dictionary()
# Builds a python dictionary that contains config info by Site-> Unit Name-> Config details
def build_master_config_dictionary():
master_json_file_dict = {}
for relative_fp in glob(JSON_CONFIG_DIR + '\*.json'):
try:
with open(relative_fp) as f:
filename = Path(relative_fp).stem
master_json_file_dict[filename] = json.load(f)
except Exception as e:
print(f'build_master_config_dictionary: unable to load in json file - {relative_fp}')
# MASTER_CONFIG_SITE_DICT = build_master_config_dictionary()