首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >这里有什么问题吗?

这里有什么问题吗?
EN

Stack Overflow用户
提问于 2011-07-28 16:16:56
回答 2查看 15.2K关注 0票数 0

我对编程和Python很陌生。我正在学习Python的艰难之路书。作为练习25的一部分,我编写了一个脚本:

代码语言:javascript
复制
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时,我得到:

代码语言:javascript
复制
> Traceback (most recent call last):
>  File "(stdin)", line 1, in `<module>`
> ImportError: No module named ex25

在Computer\Properties\Advanced\Environment变量下,我添加了系统变量:

PYTHONPATH

C:\Python27 27

这没什么用。我做错了什么?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-07-28 16:18:53

C:\Users\Brandon\Experiment\Python_ex不在系统路径上,因此python不知道在哪里可以找到ex25模块。

代码语言:javascript
复制
import sys
sys.path.append(r'C:\Users\Brandon\Experiment\Python_ex')
票数 5
EN

Stack Overflow用户

发布于 2014-05-06 13:11:11

我只是遇到了同样的问题。因为我的文件保存在Desktop/mint/ex25.py中。我首先通过命令directory /mint将目录更改为桌面。而不是按推荐的方式运行。它会解决它的。要返回到旧目录,请使用命令cd -。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6862214

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档