Skip to content

Commit

Permalink
update config_handler.py (#202)
Browse files Browse the repository at this point in the history
Co-authored-by: cuiyaning <[email protected]>
  • Loading branch information
emotionor and emotionor authored Jan 2, 2024
1 parent 15e386d commit b3227e4
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions unimol_tools/unimol_tools/utils/config_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,27 @@


class YamlHandler:
'''A clss to read and write the yaml file'''
def __init__(self, file_path):
"""
A custom logger class that provides logging functionality to console and file.
:param file_path: (str) The yaml file path of the config.
"""
if not os.path.exists(file_path):
raise FileExistsError(OSError)
self.file_path = file_path
def read_yaml(self, encoding='utf-8'):
""" read yaml file and convert to easydict
:param encoding: (str) encoding method uses utf-8 by default
:return: Dict (addict), the usage of Dict is the same as dict
"""
with open(self.file_path, encoding=encoding) as f:
return Dict(yaml.load(f.read(), Loader=yaml.FullLoader))
def write_yaml(self, data, out_file_path, encoding='utf-8'):
""" write dict or easydict to yaml file(auto write to self.file_path)
:param data: (dict or Dict(addict)) dict containing the contents of the yaml file
"""
with open(out_file_path, encoding=encoding, mode='w') as f:
Expand Down

0 comments on commit b3227e4

Please sign in to comment.