2014-07-19 4 views
1

나는 각 단계를 수행하여 파이썬 하드 방법을 알아의 운동 (25)를 해결하기 위해 노력하고있어하지만 난이 오류가 계속 : 나는없음 모듈 (가져 오기 오류 파이썬 2.7)

>>> import ex25 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named ex25 

코드를 복사 - 붙여 넣기 없습니다 이 책의 사이트에서 Gedit (Linux 텍스트 편집기)로 바뀌었지만 오타가 아닌 것 같습니다.

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) 
+4

당신은'ex25.py'로 파일을 저장 했습니까? –

+2

"ex25.py"와 같은 디렉토리에 있습니까? –

답변

2

@Padraic 커닝햄과 @ 제임스 밀스 방금 가져 오기 오류를 받고, 올바른 질문을 요구하고, 아무것도 코드 오류로 암시가 없습니다. 파일이 현재 작업중인 디렉토리에 존재하는지 확인해야합니다. 대소 문자를 구분합니다.

Learnpython.org Examples , Python.org Modules Docs

+0

Padraic이 옳았습니다. 나는 우분투 초보자이고 '.py'를 쓰지 않고도 터미널에서 스크립트를 실행할 수 있다는 사실 때문에 처음에는 이것을 '.py'로 저장할 필요가 없다고 생각하게 만들었습니다. 답변 해 주셔서 감사합니다. – Miprog12

관련 문제