Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用脚本导入GASP时遇到困难_Python_Gasp - Fatal编程技术网

Python 使用脚本导入GASP时遇到困难

Python 使用脚本导入GASP时遇到困难,python,gasp,Python,Gasp,使用解释器模式,gasp import*中的会运行,但当我将其放入脚本中时,它不会运行。我直接从第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

使用解释器模式,gasp import*中的
会运行,但当我将其放入脚本中时,它不会运行。我直接从第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
ben@ubuntu:~$python'/home/ben/Documents/python/gasp.py'
回溯(最近一次呼叫最后一次):
文件“/home/ben/Documents/Python/gasp.py”,第1行,在
从gasp进口*
文件“/home/ben/Documents/Python/gasp.py”,第3行,在
begin_graphics()
名称错误:未定义名称“开始图形”

重命名脚本。您正在隐藏真正的
gasp
模块:

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

from gasp import *
它正在尝试导入自身,因为您称它为
gasp.py

重命名脚本并不能解决此问题

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
ben@ubuntu:~$python'/home/ben/Documents/python/gapstest.py'
回溯(最近一次呼叫最后一次):
文件“/home/ben/Documents/Python/gapstest.py”,第1行,在
从gasp进口*
文件“/home/ben/Documents/Python/gasp.py”,第3行,在
名称错误:未定义名称“开始图形”

您再次包括了“/home/ben/Documents/Python/gasp.py”。删除此副本:)

+1,用于在未被询问的情况下对您的第一个问题进行完整的回溯,从而为我们提供足够的信息来调试您的问题。