I have a YAML file i.e.
test.yml which looks like the following:
details: server1: abc.host.com port: 80
I am trying to read these keys and assign to a string using Python with code:
#!/usr/bin/python import os import yaml with open('test.yml', 'r') as cfg: yamlcfg=yaml.load(cfg) str1 = "Hostname: " + (yamlcfg['details']['server1']) print str1
When I run this code. I get error:
TypeError: list indices must be integers, not str
What am I doing wrong?