hi, i just started to learn xml using python and i'm getting error when opening the output xml. it doesnt give error when running. i also tried to use python to output to a text file and it works without any error. Pls advise me how i can rectify the error when opening the output xml. attached is my code, output in text file and output in xml. thanks tcl
import elementtree.ElementTree as ET
lspeed=2 tspeed=3 f=open("out.txt", "w") for port in range(1,9): print "Port %d" %port root = ET.Element("Test") f.write("Port %d\n" %port) head1 = ET.SubElement(root, "Default_Config", Port=str(port)) print "Link speed: %d" %lspeed f.write("Link speed: %d\n" %lspeed) title = ET.SubElement(head1, "LINK") title.text = str(lspeed) print "Target speed: %d" %tspeed f.write("Target speed: %d\n" %tspeed) title = ET.SubElement(head1, "Target Speed") title.text = str(tspeed) tree = ET.ElementTree(root) tree.write("C:\\Python25\\myscript\\cmm\\port1.xml") f.close()
Port 1 Link speed: 2 Target speed: 3 Port 2 Link speed: 2 Target speed: 3 Port 3 Link speed: 2 Target speed: 3 Port 4 Link speed: 2 Target speed: 3 Port 5 Link speed: 2 Target speed: 3 Port 6 Link speed: 2 Target speed: 3 Port 7 Link speed: 2 Target speed: 3 Port 8 Link speed: 2 Target speed: 3
port1.xml
Description: Binary data
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor