Python 3 - XML/YAML

Updated: 2018-12-09

YAML

yaml module can be used to easily read or write yaml files.

Install

$ pip install yaml

Import

>>> import yaml

Read from File

>>> yaml.load(open("test.yml"))

Write to File

>>> yaml.dump(obj)

XML

Convert XML to JSON

Install xmltodict

$ sudo pip install xmltodict

Python Code:

import json
import xmltodict

s = open("foo.xml").read()
d = xmltodict.parse(s)
json.dump(d, open("bar.json",'w'))