2

Using interpreter mode, from gasp import * runs, but when I place it in a script it doesn't. I'm copying this straight from chapter 4 of How to Think Like a Computer Scientist: Learning with Python (under heading 4.11. GASP).

Script:

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()

Terminal:

ben@ubuntu:~$ 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
ben
  • 23
  • 2
  • +1 for including the full traceback on your first question without being asked, and so actually giving us enough info to debug your problem. – agf Sep 17 '11 at 05:11

2 Answers2

1

Rename your script. You're hiding the real gasp module:

ben@ubuntu:~$ python '/home/ben/Documents/Python/gasp.py' 

When you

from gasp import *

it's trying to import itself because you called it gasp.py.

agf
  • 171,228
  • 44
  • 289
  • 238
0

Renaming the script does not solve the problem.

ben@ubuntu:~$ 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

You included "/home/ben/Documents/Python/gasp.py" again. Delete this copy :)

b2ag
  • 53
  • 7