forked from ai-med/quickNAT_pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
28 lines (21 loc) · 747 Bytes
/
settings.py
File metadata and controls
28 lines (21 loc) · 747 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
import ast
import configparser
from collections.abc import Mapping
class Settings(Mapping):
def __init__(self, setting_file='settings.ini'):
config = configparser.ConfigParser()
config.read(setting_file)
self.settings_dict = _parse_values(config)
def __getitem__(self, key):
return self.settings_dict[key]
def __len__(self):
return len(self.settings_dict)
def __iter__(self):
return self.settings_dict.items()
def _parse_values(config):
config_parsed = {}
for section in config.sections():
config_parsed[section] = {}
for key, value in config[section].items():
config_parsed[section][key] = ast.literal_eval(value)
return config_parsed