注意:.yaml文件中每个’ : '后都有一个空格
config = Config(args)
class Config(dict):
def __init__(self, args):
# open the file of .yaml
with open(args.yaml_path, 'r') as f:
self._dict = yaml.load(f.read()) # Load the dictionary
def __getattr__(self, name): # gets the value of the nested(嵌套的) dictionary
if self._dict.get(name) is not None:
return self._dict[name]
return None
调用: