-
-
Save kennethlove/633ec23a2cbd7bc3d40a 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
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