如何在不编写完整文件的情况下更改元素field1.text
的文本? (python 2.5)。
import xml.etree.cElementTree as ET
import urllib2
import os
file("c:\Python25\wxTime.xml", 'w')
root = ET.Element("root")
doc = ET.SubElement(root, "doc")
field1 = ET.SubElement(doc, "wxpageTime")
field1.set("name", "lastUpdate")
field1.text = "Thu May 10 02:00:00 2012"
tree = ET.ElementTree(root)
tree.write("c:\Python25\wxTime.xml")
答案 0 :(得分:1)