以下两个软件包根据使用情况如何变化? [英] How do the below two packages vary according to usage?

查看:63
本文介绍了以下两个软件包根据使用情况如何变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用它们作为软件包导入时,它们两者都包含库中的ElementTree.py程序有什么区别

import xml.etree.ElementTree as etree
from elementtree import ElementTree as etree

如果我用另一个替换它会显示错误,为什么?

If i replace one with other it shows an error, why?

推荐答案

xml。 etree.ElementTree 自Python 2.5以来就是Python标准库的一部分: https://docs.python.org/2/library/xml.etree.elementtree.html

xml.etree.ElementTree is part of the Python standard library since Python 2.5: https://docs.python.org/2/library/xml.etree.elementtree.html.

要使elementtree的作为etree导入ElementTree 起作用,必须单独安装ElementTree。如果您需要将该库与旧版本的Python一起使用,则曾经有必要这样做(请参见 http:// effbot.org/zone/element-index.htm )。使用Python 2.7,没有理由这样做。

For from elementtree import ElementTree as etree to work, you have to install ElementTree separately. This was once necessary if you needed to use the library with older versions of Python (see http://effbot.org/zone/element-index.htm). With Python 2.7, there is no reason to do this.

因此,请忘记 elementtree.ElementTree 并仅使用 xml.etree.ElementTree

So forget about elementtree.ElementTree and use only xml.etree.ElementTree.

这篇关于以下两个软件包根据使用情况如何变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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