当我尝试导入以下模块(ex25.py):模块没有被正确导入在Python
def break_words(stuff):
"""This function will break up words for us."""
words = stuff.split(' ')
return words
所有我得到的回复是这样的:
>>>import ex25
并没有什么回.. .no提示我做错了什么...它几乎就像它甚至没有读取模块...
当我尝试导入以下模块(ex25.py):模块没有被正确导入在Python
def break_words(stuff):
"""This function will break up words for us."""
words = stuff.split(' ')
return words
所有我得到的回复是这样的:
>>>import ex25
并没有什么回.. .no提示我做错了什么...它几乎就像它甚至没有读取模块...
,我认为你应该输入所有以>>>
import ex25
sentence = "All good things come to those who wait."
words = ex25.break_words(sentence)
words
您键入的最后一行,words
后,你会看到从解释一些输出
我不认为你实际上做了什么错事; import
声明通常不会产生任何输出(它只会在是错误时抱怨)。试试:
>>> dir(ex25)
这应该给出从ex25
模块导出的名称列表。
#后,我进入应该看到下面的6 >>>句话在终端 >>>进口EX25 #IM提示= “所有的好事都会发生在那些等待的人身上。” 7 >>> words = ex25.break_words(sentence) 8 >>> word – 2011-04-13 03:23:30
不,这就是你应该*键入*下一个。在>>> >>>之后的所有内容都是您输入到Python解释器中的一行。 – 2011-04-13 03:28:58
类型:
import ex25
ex25.break_words('some example')
或另一种方式:
from ex25 import break_words
break_words('some example')
顺便说一句,如果模块没有被发现,你会得到一个ImportError异常
非常感谢你@gnibbler – 2011-04-13 03:50:07
@Colin,非常欢迎 – 2011-04-13 07:00:06