簡體   English   中英

模塊沒有在python中正確導入

[英]module not being imported correctly in python

當我嘗試導入以下模塊(ex25.py)時:

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

我得到的回報是:

>>>import ex25

什么都沒有回來...沒有提示我做錯了什么......它幾乎就像它甚至沒有閱讀模塊......

我不認為你真的做錯了什么; import語句通常不產生任何輸出(只抱怨,如果什么錯誤的)。 嘗試:

>>> dir(ex25)

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

我認為你應該輸入以>>>開頭的所有行

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

您鍵入的最后一行之后, words ,你應該能看到一些解釋輸出

類型:

import ex25
ex25.break_words('some example')

或另一種方式:

from ex25 import break_words
break_words('some example')

順便說一句,如果找不到該模塊,您將收到ImportError異常

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM