-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmisc.py
More file actions
23 lines (19 loc) · 787 Bytes
/
misc.py
File metadata and controls
23 lines (19 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import yaml
class DictConfig(object):
"""Creates a Config object from a dict
such that object attributes correspond to dict keys.
"""
def __init__(self, config_dict):
for key, val in config_dict.items():
# Flatten any list of lists
if isinstance(val, list) and any(isinstance(i, list) for i in val):
# Flatten the list of lists
val = [item for sublist in val for item in sublist]
self.__setattr__(key, val)
def __str__(self):
return '\n'.join(f"{key}: {val}" for key, val in self.__dict__.items())
def get_config(fname):
with open(fname, 'r') as stream:
config_dict = yaml.load(stream, Loader=yaml.FullLoader)
config = DictConfig(config_dict)
return config