【发布时间】:2009-09-26 13:49:42
【问题描述】:
抱歉,我无法在标题中更好地描述我的问题。
我正在尝试学习 Python,遇到了这种奇怪的行为,希望有人能向我解释一下。
我正在运行 Ubuntu 8.10 和 python 2.5.2
首先我导入 xml.dom
然后我创建一个 minidom 的实例(使用它的完全 qaulified 名称 xml.dom.minidom)
这失败了,但是如果我再次运行同一行,它就可以了!
见下文:
$> python
Python 2.5.2 (r252:60911, Oct 5 2008, 19:29:17)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import xml.dom
>>> xml.dom.minidom.parseString("<xml><item/></xml>")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'minidom'
>>> xml.dom.minidom.parseString("<xml><item/></xml>")
<xml.dom.minidom.Document instance at 0x7fd914e42fc8>
我在另一台机器上尝试过,如果一直失败。
【问题讨论】:
-
该问题在 Python 2.6.2、Ubuntu 9.04 上可重现
-
未在雪豹上确认,手动安装了 python 2.4.6。然而有趣的问题。
-
这是第一次使用 python 2.6.2, Ubuntu 9.04
标签: python