yaml文件读写操作
1.yaml读操作
# yaml文件讀操作
fin = open('config.yaml', 'r', encoding='utf-8')
msg = yaml.load(fin, Loader=yaml.FullLoader)[0]
print(msg, type(msg))
fin.close()
2.yaml写操作
# yaml文件讀操作
fin = open('config.yaml', 'r', encoding='utf-8')
msg = yaml.load(fin, Loader=yaml.FullLoader)[0]
print(msg, type(msg))
fin.close()
# 写入操作
fin = open('config.yaml', 'w', encoding='utf-8')
msg['secret_key_holder1']['test_holder1_secret_key'] = 'gaojs'
yaml.dump(msg, fin)
result = msg.get('secret_key_holder1').get('test_holder1_secret_key')
print(result)
fin.close()