import yaml
import os
config_file = "config.yaml"
test_dict = {"a": 1, "b": 2}
if not os.path.exists(config_file):
with open(config_file, "w", encoding="utf8") as w:
pass
with open(config_file, "w", encoding="utf-8") as w:
yaml.dump(test_dict, w)
with open(config_file, 'r', encoding='utf8') as f:
config = f.read()
yaml_data = yaml.safe_load(config)
print(yaml_data)
08-13
894
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)