python replace list of ips from yaml file with new list

Solutions on MaxInterview for python replace list of ips from yaml file with new list by the best coders in the world

showing results for - "python replace list of ips from yaml file with new list"
Lesley
16 Apr 2016
1import yaml
2
3fname = "some.yaml"
4
5stream = open(fname, 'r')
6data = yaml.load(stream)
7
8data['instances'][0]['host'] = '1.2.3.4'
9data['instances'][0]['username'] = 'Username'
10data['instances'][0]['password'] = 'Password'
11
12with open(fname, 'w') as yaml_file:
13    yaml_file.write( yaml.dump(data, default_flow_style=False))
14
similar questions