使用解释器模式,from gasp import * 运行,但是当我将它放在脚本中时它不会运行。我是从 How to Think Like a Computer Scientist: Learning with Python 的第 4 章直接复制的(在标题 4.11.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()
终端:
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
请您参考如下方法:
重命名您的脚本。你隐藏了真正的 gasp 模块:
ben@ubuntu:~$ python '/home/ben/Documents/Python/gasp.py'
当你
from gasp import *
它正在尝试导入 自身,因为您将其命名为gasp.py。
