手机
当前位置:查字典教程网 >脚本专栏 >python >python写入xml文件的方法
python写入xml文件的方法
摘要:本文实例讲述了python写入xml文件的方法。分享给大家供大家参考。具体分析如下:本范例通过xml模块对xml文件进行写入操作fromxm...

本文实例讲述了python写入xml文件的方法。分享给大家供大家参考。具体分析如下:

本范例通过xml模块对xml文件进行写入操作

from xml.dom.minidom import Document doc = Document() people = doc.createElement("people") doc.appendChild(people) aperson = doc.createElement("person") people.appendChild(aperson) name = doc.createElement("name") aperson.appendChild(name) personname = doc.createTextNode("Annie") name.appendChild(personname) filename = "people.xml" f = open(filename, "w") f.write(doc.toprettyxml(indent=" ")) f.close()

希望本文所述对大家的Python程序设计有所帮助。

【python写入xml文件的方法】相关文章:

python sqlobject(mysql)中文乱码解决方法

使用python提取html文件中的特定数据的实现代码

Python操作列表的常用方法分享

vc6编写python扩展的方法分享

python正则表达式修复网站文章字体不统一的解决方法

Python实现扫描指定目录下的子目录及文件的方法

python实现文件名批量替换和内容替换

Python中的yield浅析

Python文件夹与文件的操作实现代码

python del()函数用法

精品推荐
分类导航