cElementtree 和 ElementTree 有什么区别? [英] What are the Difference between cElementtree and ElementTree?

查看:37
本文介绍了cElementtree 和 ElementTree 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对dom略知一二,想了解ElementTree.Python 2.6 有一个较旧的 ElementTree 实现,但仍然可用.但是,看起来它带有两个不同的类:xml.etree.ElementTree 和 xml.etree.cElementTree.有人会这么好心地告诉我他们的差异吗?谢谢.

I know a little of dom, and would like to learn about ElementTree. Python 2.6 has a somewhat older implementation of ElementTree, but still usable. However, it looks like it comes with two different classes: xml.etree.ElementTree and xml.etree.cElementTree. Would someone please be so kind to enlighten me with their differences? Thank you.

推荐答案

它是同一个库(相同的 API,相同的特性)但是 ElementTree 是用 Python 实现的,而 cElementTree 是用 C 实现的.

It is the same library (same API, same features) but ElementTree is implemented in Python and cElementTree is implemented in C.

如果可以,请使用 C 实现,因为它针对快速解析和低内存使用进行了优化,并且比 Python 实现快 15-20 倍.

If you can, use the C implementation because it is optimized for fast parsing and low memory use, and is 15-20 times faster than the Python implementation.

如果您处于有限的环境中(不允许加载 C 库),请使用 Python 版本.

Use the Python version if you are in a limited environment (C library loading not allowed).

这篇关于cElementtree 和 ElementTree 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆