Created
September 11, 2012 09:24
-
-
Save benhosmer/3697171 to your computer and use it in GitHub Desktop.
Parsing yaml into a python dictionary.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f = open('user.yaml') | |
dataMap = yaml.load(f) | |
f.close() | |
print "" | |
print "=-----------=" | |
print "dataMap is a ", type(dataMap), dataMap | |
print "=-----------=" | |
print "main items are", type(dataMap['main']), dataMap['main'] | |
print "=-----------=" | |
print "main is a list, the first item is a dictionary", type(dataMap['main'][0]), dataMap['main'][0] | |
print "=-----------=" | |
print "main[0] is a dict, the first item is", dataMap['main'][0]['users'][0] | |
""" | |
Sample YAML File: | |
- users: | |
- joe | |
- mike | |
- sally | |
- path: | |
- /Users/me/files/ | |
- text.files | |
- search_phrases: | |
- Invalid users | |
- Failed password | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@D-Pkya you have a break in the for loop causing the loop to end after the first iteration.