对不起,我不能在标题中更好地描述我的问题。Python - 同一行代码仅在第二次调用时才起作用?
我想学习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的 – jfs 2009-09-26 14:00:33
雪豹未确认,蟒蛇2.4.6手动安装。但有趣的问题。 – 2009-09-26 15:02:10
这个工程使用python 2.6.2,Ubuntu 9.04的 – 2009-09-26 18:29:42