📜  python 用新列表替换 yaml 文件中的 ips 列表 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:44.998000             🧑  作者: Mango

代码示例1
import yaml

fname = "some.yaml"

stream = open(fname, 'r')
data = yaml.load(stream)

data['instances'][0]['host'] = '1.2.3.4'
data['instances'][0]['username'] = 'Username'
data['instances'][0]['password'] = 'Password'

with open(fname, 'w') as yaml_file:
    yaml_file.write( yaml.dump(data, default_flow_style=False))