上の Python ドキュメントturtle
からサンプル コードの最初の部分を実行しようとすると、次のようになります。
from turtle import *
color('red', 'yellow')
begin_fill()
while True:
forward(200)
left(170)
if abs(pos()) < 1:
break
end_fill()
done()
私は得るNameError
:
NameError: 名前 'color' が定義されていません
モジュールを微調整しimport
て手動で指定しても機能しません。
import turtle
turtle.color('red', 'yellow')
turtle.begin_fill()
while True:
turtle.forward(200)
turtle.left(170)
if abs(turtle.pos()) < 1:
break
turtle.end_fill()
turtle.done()
ドキュメントに従って、明らかに含まれているPython v3.2.3を使用してturtle.color
います。Pythontkinter
も同様に機能するため、サポート付きでインストールさimport tkinter
れます。
完全なトレースは次のとおりです。
Traceback (most recent call last):
File "<path name that contains no spaces>/turtle.py", line 1, in <module>
from turtle import *
File "<path name that contains no spaces>\turtle.py", line 2, in <module>
color('red', 'yellow')
NameError: name 'color' is not defined
奇妙です。コマンド ラインまたは IDLE のいずれかでシェルに入り、一度に 1 つずつコマンドを入力すると、次のようになります。
>>> from turtle import *
>>> color('red', 'yellow')
問題ありません。IDLE で新しいウィンドウを開き、すべてのコマンドを入力して、スクリプトを実行したときだけです。