Created
December 12, 2014 22:17
-
-
Save lindsm/e719705353124b965e90 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(xml_file): | |
''' xml.file -> list | |
For every sin in a given xml_file, return a list containing the FQDN. | |
''' | |
tree = ET.parse(xml_file) | |
root = tree.getroot() | |
sins = [] | |
for server in root.iter('sin'): | |
hostname = server.get('host') | |
sins.append(hostname) | |
else: | |
return sins | |
def count_hosts(xml_file): | |
''' string --> int | |
For a given xml_file return the integer count of sins. | |
count_hosts(env.xml) | |
>>>24 | |
''' | |
tree = ET.parse(xml_file) | |
root = tree.getroot() | |
count = 0 | |
for server in root.iter('sin'): | |
count += 1 | |
else: | |
return count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment