2

インタープリターモードを使用するとfrom gasp import *実行されますが、スクリプトに配置すると実行されません。How to Think Like a Computer Scientist: Learning with 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
4

2 に答える 2

1

スクリプトの名前を変更します。実際のgaspモジュールを非表示にしています:

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

あなたが

from gasp import *

importあなたがそれを呼んだので、それはそれ自身にしようとしていますgasp.py

于 2011-09-17T05:07:54.367 に答える
0

スクリプトの名前を変更しても問題は解決しません。

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

「/home/ben/Documents/Python/gasp.py」を再度含めました。このコピーを削除してください:)

于 2011-09-18T07:15:35.670 に答える