没有名为的模块(导入错误Python 2.7)
我试图通过遵循每一个步骤来解决“学习Python”中的练习25,但我一直遇到以下错误:没有名为的模块(导入错误Python 2.7),python,ubuntu,gnome,gedit,Python,Ubuntu,Gnome,Gedit,我试图通过遵循每一个步骤来解决“学习Python”中的练习25,但我一直遇到以下错误: >>> import ex25 Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named ex25 @Padraic Cunningham和@James Mills提出了正确的问题,您只是得到了一个导入错误,没有什么可以暗
>>> import ex25
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named ex25
@Padraic Cunningham和@James Mills提出了正确的问题,您只是得到了一个导入错误,没有什么可以暗示代码错误。您需要确保文件存在于您正在使用的目录中。请记住,它是区分大小写的 ,,
您是否将文件另存为
ex25.py
?您是否与ex25.py
位于同一目录下?Padraic是正确的。我是一个Ubuntu新手,你可以从终端运行一个脚本而不用写“.py”,这让我觉得我不必首先将它保存为“.py”。谢谢你的回答。
def break_words(stuff):
"""This function will break up words for us."""
words = stuff.split(' ')
return words
def sort_words(words):
"""Sorts the words."""
return sorted(words)
def print_first_word(words):
"""Prints the first word after popping it off."""
word = words.pop(0)
print word
def print_last_word(words):
"""Prints the last word after popping it off."""
word = words.pop(-1)
print word
def sort_sentence(sentence):
"""Takes in a full sentence and returns the sorted words."""
words = break_words(sentence)
return sort_words(words)
def print_first_and_last(sentence):
"""Prints the first and last words of the sentence."""
words = break_words(sentence)
print_first_word(words)
print_last_word(words)
def print_first_and_last_sorted(sentence):
"""Sorts the words then prints the first and last one."""
words = sort_sentence(sentence)
print_first_word(words)
print_last_word(words)