gpt4 book ai didi

python - 难以使用脚本导入 GASP

转载 作者:太空宇宙 更新时间:2023-11-04 06:26:45 24 4
gpt4 key购买 nike

使用解释器模式,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

关于python - 难以使用脚本导入 GASP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7452508/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com