开发者

module not being imported correctly in python

when i attempt to import the following module (ex25.py):

def break_words(stuff): 
    """This f开发者_Go百科unction will break up words for us."""
    words = stuff.split(' ')
    return words

all i get back is this:

>>>import ex25

and nothing back...no prompt as to what i did wrong...its almost like it is not even reading the module...


I think you are supposed to type all the lines that start with >>>

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

after you type the last line, words, you should see some output from the interpreter


I don't think you've actually done anything wrong; the import statement normally does not produce any output (it only complains if there is something wrong). Try:

>>> dir(ex25)

That should give a list of the names exported from the ex25 module.


type:

import ex25
ex25.break_words('some example')

or another way:

from ex25 import break_words
break_words('some example')

btw if the module wasn't found you would get an ImportError exception

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜