使用解释器模式from gasp import *
运行,但是当我将它放在脚本中时它不会。我直接从如何像计算机科学家一样思考:使用 Python 学习(标题 4.11. GASP 下)的第 4 章复制了这一点。
脚本:
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