我对编程和Python很陌生。我正在学习Python的艰难之路书。作为练习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.
当我从ex25导入python.exe时,我得到:
> Traceback (most recent call last):
> File "(stdin)", line 1, in `<module>`
> ImportError: No module named ex25在Computer\Properties\Advanced\Environment变量下,我添加了系统变量:
PYTHONPATH
C:\Python27 27
这没什么用。我做错了什么?
发布于 2011-07-28 16:18:53
C:\Users\Brandon\Experiment\Python_ex不在系统路径上,因此python不知道在哪里可以找到ex25模块。
import sys
sys.path.append(r'C:\Users\Brandon\Experiment\Python_ex')发布于 2014-05-06 13:11:11
我只是遇到了同样的问题。因为我的文件保存在Desktop/mint/ex25.py中。我首先通过命令directory /mint将目录更改为桌面。而不是按推荐的方式运行。它会解决它的。要返回到旧目录,请使用命令cd -。
https://stackoverflow.com/questions/6862214
复制相似问题