2

我正在尝试使用海龟的 python 导入,但出现错误:

Traceback (most recent call last):
  File "turtle.py", line 1, in <module>
    import turtle
  File "/turtle.py", line 32, in <module>
    turtle.pensize(2)
AttributeError: 'module' object has no attribute 'pensize'

python 是自带turtle 还是需要单独下载?

我的python是2.7.2

4

2 回答 2

8

你调用了你的文件turtle.py,所以import turtle导入你的程序,而不是你想要的模块。

重命名您的程序并删除所有turtle.py[co]文件。

于 2013-02-20T18:29:10.647 回答
0

使用turtle.py 导致了这里的问题。废弃它并改用它

import turtle
turtlename = turtle.Turtle()
wn = turtle.Screen()

完成此操作后,请使用基本的海龟命令,例如

turtlename.forward(90)
于 2013-05-10T09:02:27.240 回答