easycore.common.config

class easycore.common.config.CfgNode(init_dict: dict = None, copy=True)[source]

Bases: dict

Config Node

__init__(init_dict: dict = None, copy=True)[source]
Parameters:
  • init_dict (dict) – a possibly-nested dictionary to initialize the CfgNode.
  • copy (bool) – if this option is set to False, the CfgNode instance will share the value with the init_dict, otherwise the contents of init_dict will be deepcopied.
freeze(frozen: bool = True)[source]

freeze or unfreeze the CfgNode and all of its children

Parameters:frozen (bool) – freeze or unfreeze the config
is_frozen()[source]

get the state of the config.

Returns:bool – whether the config tree is frozen.
copy()[source]

deepcopy this CfgNode

Returns:CfgNode
merge(cfg)[source]

merge another CfgNode into this CfgNode, the another CfgNode will override this CfgNode.

Parameters:cfg (CfgNode) –
save(save_path, encoding='utf-8')[source]

save the CfgNode into a yaml file

Parameters:save_path
classmethod open(file, encoding='utf-8')[source]

load a CfgNode from file.

Parameters:
  • file (io.IOBase or str) – file object or path to the yaml file.
  • encoding (str) –
Returns:

CfgNode

classmethod load(yaml_str: str)[source]

load a CfgNode from a string of yaml format

Parameters:yaml_str (str) –
Returns:CfgNode
classmethod dump(cfg, stream=None, encoding=None, **kwargs)[source]

dump CfgNode into yaml str or yaml file

Note

if stream option is set to non-None object, the CfgNode will be dumpped into stream and return None, if stream option is not given or set to None, return a string instead.

Parameters:
Returns:

None or str