對不起,我不能在標題中更好地描述我的問題。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