2011-04-13 45 views
1

當我嘗試導入以下模塊(ex25.py):模塊沒有被正確導入在Python

def break_words(stuff): 
    """This function will break up words for us.""" 
    words = stuff.split(' ') 
    return words 

所有我得到的回覆是這樣的:

>>>import ex25 

並沒有什麼回.. .no提示我做錯了什麼...它幾乎就像它甚至沒有讀取模塊...

回答

2

,我認爲你應該輸入所有以>>>

import ex25 
sentence = "All good things come to those who wait." 
words = ex25.break_words(sentence) 
words 

您鍵入的最後一行,words後,你會看到從解釋一些輸出

+0

非常感謝你@gnibbler – 2011-04-13 03:50:07

+0

@Colin,非常歡迎 – 2011-04-13 07:00:06

2

我不認爲你實際上做了什麼錯事; import聲明通常不會產生任何輸出(它只會在錯誤時抱怨)。試試:

>>> dir(ex25) 

這應該給出從ex25模塊導出的名稱列表。

+0

#後,我進入應該看到下面的6 >>>句話在終端 >>>進口EX25 #IM提示= 「所有的好事都會發生在那些等待的人身上。」 7 >>> words = ex25.break_words(sentence) 8 >>> word – 2011-04-13 03:23:30

+1

不,這就是你應該*鍵入*下一個。在>>> >>>之後的所有內容都是您輸入到Python解釋器中的一行。 – 2011-04-13 03:28:58

0

類型:

import ex25 
ex25.break_words('some example') 

或另一種方式:

from ex25 import break_words 
break_words('some example') 

順便說一句,如果模塊沒有被發現,你會得到一個ImportError異常