首页 > 编程语言 > 详细

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

时间:2017-12-28 22:24:18      阅读:855      评论:0      收藏:0      [点我收藏+]

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区别

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!