Question

I am trying to use a python import of turtle but i get an error:

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'

Does the python come with turtle or i have to download it separately?

My python is 2.7.2

Était-ce utile?

La solution

You called your file turtle.py, so import turtle imports your program, not the module you want.

Rename your program and delete any turtle.py[co] files.

Autres conseils

using turtle.py is causing the problem here. scrap that and use this instead

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

once you have done this use basic turtle comands like

turtlename.forward(90)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top