我是编程和 Python 的新手。我正在关注Learn Python the Hard Way一书。作为练习 25 的一部分,我编写了一个脚本:
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 words 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)`
我把它从 gedit 保存为
ex25.py
在路径下
C:\Users\Brandon\Experiment\Python_ex
我正在运行 64 位 Windows 7。
当我从 python.exe 导入 ex25 时,我得到:
> Traceback (most recent call last):
> File "(stdin)", line 1, in `<module>`
> ImportError: No module named ex25
在 Computer\Properties\Advanced\Environment Variables 下,我添加了系统变量:
蟒蛇路径
C:\Python27
那没有帮助。我究竟做错了什么?