[Python] python写入xml文件演示代码 →→→→→进入此内容的聊天室

来自 , 2021-02-25, 写在 Python, 查看 115 次.
URL http://www.code666.cn/view/e3c9cb08
  1. from xml.dom.minidom import Document
  2. doc = Document()
  3. people = doc.createElement("people")
  4. doc.appendChild(people)
  5. aperson = doc.createElement("person")
  6. people.appendChild(aperson)
  7. name = doc.createElement("name")
  8. aperson.appendChild(name)
  9. personname = doc.createTextNode("Annie")
  10. name.appendChild(personname)
  11. filename = "people.xml"
  12. f = open(filename, "w")
  13. f.write(doc.toprettyxml(indent="   "))
  14. f.close()
  15. #//python/7379

回复 "python写入xml文件演示代码"

这儿你可以回复上面这条便签

captcha