为了便于阅读,我喜欢在Python中使用完整的名称空间。我想知道为什么这不起作用的XML库。我的数字import xml
也会导入etree和命名空间中的所有内容。至少这是我注意到其他模块的行为。Python import xml不包含xml.etree.ElementTree
$ ptpython
>>> import xml
>>> dir(xml.etree.ElementTree)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'etree'
'module' object has no attribute 'etree'
>>> import xml.etree.ElementTree
>>> dir(xml.etree.ElementTree)
['Comment', 'Element', 'ElementPath', 'ElementTree', 'HTML_EMPTY', 'PI',...]
两个问题:
- 这究竟是为什么用XML库?
- 有没有办法像
import xml
那样简单地导入它?
这个答案是相当相关的:http://stackoverflow.com/a/7948672/771848。 – alecxe