2011-09-17 3 views
2

인터프리터 모드를 사용하면 from gasp import *이 실행되지만 스크립트에 배치 할 때 그렇지 않습니다. 나는 이것을 제 4 장 How to Think Like a Computer Scientist: Learning with Python (4.11. GASP 아래에 있음)에서 바로 복사하고있다.난이도 : 스크립트를 사용하여 GASP 가져 오기

스크립트 :

from gasp import * 

begin_graphics() 

Circle((200, 200), 60) 
Line((100, 400), (580, 200)) 
Box((400, 350), 120, 100) 

update_when('key_pressed') 
end_graphics() 

터미널 :

[email protected]:~$ python '/home/ben/Documents/Python/gasp.py' 
Traceback (most recent call last): 
File "/home/ben/Documents/Python/gasp.py", line 1, in <module> 
from gasp import * 
File "/home/ben/Documents/Python/gasp.py", line 3, in <module> 
begin_graphics() 
NameError: name 'begin_graphics' is not defined 
+0

+1 질문을하지 않고 첫 번째 질문에 전체 추적을 포함 시켜서 실제로 문제를 디버깅 할 수있는 충분한 정보를 제공합니다. – agf

답변

1

이 스크립트의 이름을 바꿉니다. 당신은 진짜 gasp 모듈을 숨기고있어 :

[email protected]:~$ python '/home/ben/Documents/Python/gasp.py' 

당신이 그것을 gasp.py라고 때문에

from gasp import * 

그 자체 import하려고.

0

스크립트의 이름을 바꾸어도 문제가 해결되지 않습니다.

[email protected]:~$ python '/home/ben/Documents/Python/gasptest.py' 
Traceback (most recent call last): 
File "/home/ben/Documents/Python/gasptest.py", line 1, in <module> 
from gasp import * 
File "/home/ben/Documents/Python/gasp.py", line 3, in <module> 
NameError: name 'begin_graphics' is not defined 

는 다시 "/home/ben/Documents/Python/gasp.py"를 포함. 이 사본을 삭제하십시오 :)

+0

어리석은 me :) 감사합니다. – ben