Skip to content

Instantly share code, notes, and snippets.

@kennethlove
Forked from lindsm/gist:e719705353124b965e90
Last active August 29, 2015 14:11
Show Gist options
  • Save kennethlove/633ec23a2cbd7bc3d40a to your computer and use it in GitHub Desktop.
Save kennethlove/633ec23a2cbd7bc3d40a to your computer and use it in GitHub Desktop.
import xml.etree.ElementTree as ET
def get_hosts(tree_root):
'''Takes an ETree root
For every sin in a given xml_file, return a list containing the FQDN.
'''
return [server.get('host') for server in tree_root.iter('sin')]
def count_hosts(tree_root):
'''Takes an ETree root
For a given xml_file return the integer count of sins.
count_hosts(env.xml)
>>>24
'''
return len(tree_root.iter('sin'))
tree = ET.parse(some_xml_file)
root = tree.getroot()
hosts = get_hosts(root)
hosts_count = count_hosts(root)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment