import os try: import xml.etree.ElementTree as ET # python 2.5 except ImportError: try: import cElementTree as ET # cElementTree is faster except ImportError: import elementtree.ElementTree as ET # fallback on regular ElementTree def log_feature_types(feature_types, file_name): root = ET.Element("feature_types") for feature_type in feature_types: ET.SubElement(root, "feature_type").text = feature_type f = open(file_name, 'w') f.write('') ET.ElementTree(root).write(f) f.close() def log_query_results(query_dict, file_name): root = ET.Element("query") for feature_type in query_dict: for feature in query_dict[feature_type]: result = ET.SubElement(root, "result") ET.SubElement(result, "type").text = str(feature_type.title()) ET.SubElement(result, "name").text = str(feature.name) ET.SubElement(result, "city").text = str(feature.city) ET.SubElement(result, "state").text = str(feature.state) ET.SubElement(result, "zip").text = str(feature.zipcode) ET.SubElement(result, "distance").text = \ str(round(feature.distance,2)) f = open(file_name, 'w') f.write('') f.write('') ET.ElementTree(root).write(f) f.close()