当我尝试从
Python documentation on 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: name ‘color’ is not defined
调整导入并手动指定模块也不起作用:
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. Python也支持tkinter,因为import tkinter也可以.
完整的痕迹是:
Traceback (most recent call last):
File "/turtle.py", line 1, in
from turtle import *
File "\turtle.py", line 2, in
color('red', 'yellow')
NameError: name 'color' is not defined
有多奇怪如果我输入shell,无论是命令行还是IDLE,并一次输入一个命令:
>>> from turtle import *
>>> color('red', 'yellow')
没有问题.只有当我在IDLE中打开一个新窗口时,输入所有命令,然后运行脚本.