-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcfg_base.py
More file actions
39 lines (30 loc) · 1001 Bytes
/
Copy pathcfg_base.py
File metadata and controls
39 lines (30 loc) · 1001 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
29
30
31
32
33
34
35
36
37
38
39
import copy
from collections.abc import Mapping
class cfg_base(Mapping):
def __init__(self, cfg_id= None, decorator = None, **kwargs):
self.id = cfg_id
self.decorator = decorator
for key, value in kwargs.items():
self.__setattr__( key, value)
def clone(self, **kwargs):
ins = copy.deepcopy(self)
for key, value in kwargs.items():
ins.__setattr__( key, value)
return ins
def update(self, dicts):
for key, val in dicts.items():
self.__setattr__( key, value)
return self.__dict__
def __iter__(self):
for key in self.__dict__.keys():
yield key
def __len__(self):
return len(self.__dict__)
def __getitem__(self, item):
return self.__dict__[item]
def __call__(self, **kwargs):
for key, value in kwargs.items():
self.__setattr__( key, value)
#if __name__ == '__main__':
#
# c = cfg.clone()