1

there is a python programe in c:\workspace\trutle.py,
i can run it in the python command line console,
when i open a cmd window, input python c:\workspace\trutle.py,
i get the wrong output

Traceback (most recent call last):
  File "c:\workspace\turtle.py", line 1, in <module>  
    import turtle
  File "c:\workspace\turtle.py", line 3, in <module>  
    turtle.speed(1)
AttributeError: 'module' object has no attribute 'speed'  

what is the reason? how to solve it?

import turtle
from random import randint
turtle.speed(1)
turtle.color("grey")
x=-80
for y in range(-80,80+1,10):
    turtle.penup()
    turtle.goto(x,y)
    turtle.pendown()
    turtle.forward(160)


y=80
turtle.right(90)
for x in range(-80,80+1,10):
    turtle.penup()
    turtle.goto(x,y)
    turtle.pendown()
    turtle.forward(160
2
  • 5
    Is your file named turtle.py or trutle.py? If it's named turtle, then when you do import turtle it will try to import itself. Name it something else besides a standard lib name. Commented Jan 4, 2014 at 7:39
  • i renamed it trutle_test.py,everything is ok. Commented Jan 4, 2014 at 7:40

2 Answers 2

3

Rename the turtle.py. Otherwise it prevent importing the turtle module.

Make sure to delete turtle.pyc generated.

Sign up to request clarification or add additional context in comments.

Comments

1

Just change the filename turtle.py to some other name.This may block the functionality of the default method.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.