码迷,mamicode.com
首页 > 编程语言 > 详细

python解析xml文件之xml.etree.cElementTree和xml.etree.ElementTree区别

时间:2017-12-28 23:20:05      阅读:1008      评论:0      收藏:0      [点我收藏+]

标签:节点   .com   xml文件   python   pytho   pycha   模式   方式   style   

1、解析速度

2、调试区别

使用cElementTree的话,在pycharm的debug模式下,是看不到内容的

技术分享图片

使用ElementTree,可以看到丰富信息,子节点,子节点的子节点等等,非常方便开发

技术分享图片

所以对于线上产品应该使用下面这种的方式,但是开发的时候,应该使用 import xml.etree.ElementTree as ET

try:
    import xml.etree.cElementTree as ET
except ImportError:
    import xml.etree.ElementTree as ET

tree = ET.parse(config_file)

 tree = ET.parse(config_file)或者tree = ET.fromstring(string),可以从文件或者字符串中解析到xml的结构

python解析xml文件之xml.etree.cElementTree和xml.etree.ElementTree区别

标签:节点   .com   xml文件   python   pytho   pycha   模式   方式   style   

原文地址:https://www.cnblogs.com/shengulong/p/8137893.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!