跳至内容
wiki
用户工具
登录
站点工具
搜索
工具
显示页面
修订记录
导出 PDF
反向链接
最近更改
媒体管理器
网站地图
登录
>
最近更改
媒体管理器
网站地图
您在这里:
start
»
linux
»
python
»
xml.etree.elementtree使用
您的足迹:
linux:python:xml.etree.elementtree使用
本页面只读。您可以查看源文件,但不能更改它。如果您觉得这是系统错误,请联系管理员。
====== xml.etree.ElementTree使用 ====== ===== - 创建xml root ===== 有3种方法: <code python> import xml.etree.ElementTree as ET # 方法1 tree = ET.ElementTree(element=None, file='country_data.xml') root = tree.getroot() # 方法2 tree = ET.parse('country_data.xml') root = tree.getroot() # 方法3, 使用此方式,从内存中获取xml文件内容。 # 比如可以先把所有的xml文件压缩,在程序中解压缩到内存,然后直接从内存中读取xml文件。 # 这样处理的好处是减少文件数量和整体大小,以及可选的密码或加解密支持。 fh = open('country_data.xml', 'r') # 此处使用'r' 和‘rb', ET都可以支持 fbuf = fh.read() root = ET.fromstring(fbuf) </code> ===== - 获取attrib ===== <code python> name = root.attrib['name'] </code>
linux/python/xml.etree.elementtree使用.txt
· 最后更改: 2023/03/17 10:12 由
127.0.0.1
页面工具
显示页面
修订记录
反向链接
导出 PDF
回到顶部