[docs]classATTPara:"""Class for read and write parameter file with ``yaml`` format """def__init__(self,fname:str)->None:""" :param fname: Path to parameter file :type fname: str """self.fname=fnamewithopen(fname,encoding='utf-8')asf:file_data=f.read()self.input_params=yaml.load(file_data)
[docs]defupdate_param(self,key:str,value)->None:"""Update a parameter in the YAML file. :param key: The key of parameter file to be set. Use '.' to separate the keys. :type key: str """keys=key.split('.')param=self.input_paramsforkinkeys[:-1]:param=param.setdefault(k,{})param[keys[-1]]=str2val(value)
[docs]defwrite(self,fname=None):"""write :param fname: Path to output file, for None to overwrite input file, defaults to None :type fname: str, optional """iffnameisNone:fname=self.fnamewithopen(fname,'w')asf:yaml.dump(self.input_params,f)