Created
January 19, 2017 05:29
-
-
Save ktbyers/87893253b0fb9a248791287836d2d4c2 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
''' | |
Write a Python program that creates a list. One of the elements of the list | |
should be a dictionary with at least two keys. Write this list out to a file | |
using both YAML and JSON formats. The YAML file should be in the expanded form. | |
''' | |
import yaml | |
import json | |
def main(): | |
''' | |
Write a Python program that creates a list. One of the elements of the list | |
should be a dictionary with at least two keys. Write this list out to a file | |
using both YAML and JSON formats. The YAML file should be in the expanded | |
form. | |
''' | |
yaml_file = 'my_test.yml' | |
json_file = 'my_test.json' | |
my_dict = { | |
'ip_addr': '172.31.200.1', | |
'platform': 'cisco_ios', | |
'vendor': 'cisco', | |
'model': '1921' | |
} | |
my_list = [ | |
'some string', | |
99, | |
18, | |
my_dict, | |
'another string', | |
'final string' | |
] | |
with open(yaml_file, "w") as f: | |
f.write(yaml.dump(my_list, default_flow_style=False)) | |
with open(json_file, "w") as f: | |
json.dump(my_list, f) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment