I have the following problem: matching documents in a YAML file with dict and displaying them correctly.
I have the following YAML file, which is a server ( db.yml ):
instanceId: i-aaaaaaaa environment:us-east serverId:someServer awsHostname:ip-someip serverName:somewebsite.com ipAddr:192.168.0.1 roles:[webserver,php]
I am loading this YAML file which I can do without any problems. I think I understand that.
instanceId = getInstanceId() stream = file('db.yml', 'r') dict = yaml.load_all(stream) for key in dict: if key in dict == "instanceId": print key, dict[key]
I would like the logic to work as follows:
- download yaml, map to dict
- look in each dict in the document if
instanceId matches what getInstanceId() was set, then print all the keys and values โโfor this document.
If I look at the map data structure from the command line, I get:
{'instanceId': 'i-aaaaaaaa environment:us-east serverId:someServer awsHostname:ip-someip serverName:someserver ipAddr:192.168.0.1 roles:[webserver,php]'}
I think that I could incorrectly create the data structure for the YAML file, and when the content matches the dict I lost a little.
Side note: I cannot load all the documents in this file using yaml.load() , I tried yaml.load_all() , which seems to work, but my main problem still exists.
python dictionary data-structures yaml
Zippy zeppoli
source share