2014-11-21 40 views

回答

3

您可以使用tail属性,我还没有测试,但如你预期它应该工作:

e = ET.Element('p') 
# you set the text to hello first 
e.text = "hello " 
# and you set a subelement with br, which is what you want 
br = ET.SubElement(e, 'br') 
# then using tail to append the text after br 
br.tail = ' world' 

... 

希望这有助于。

+0

它的工作原理。谢谢。 – lionel319 2014-11-25 06:24:43