[Tutor] Turtle help
Peter Otten
__peter__ at web.de
Sat Aug 29 03:47:51 EDT 2020
Carrie Udowychenko wrote:
> I am new to Python and have tried every command I can find but still do
> not seem to be able to access a turtle library and do any drawing.
>
> I have tried: import turtle
> and from turtle import *
The difference between these two forms of import is that with the first you
need qualified names...
import turtle
for i in range(4):
turtle.forward(50)
turtle.left(90)
turtle.exitonclick()
whereas the second allows you to use the names from the module directly:
from turtle import *
for i in range(4):
forward(50)
left(90)
exitonclick()
This may be more convenient for your first experiments, but will get
confusing once you import more than a single module.
> But after both of these any commands like forward or right still show
> errors and forward is not recognized. Please help
Does the error look like this?
Traceback (most recent call last):
File "turtle.py", line 1, in <module>
from turtle import *
File "/home/carrie/turtle.py", line 4, in <module>
forward(50)
NameError: name 'forward' is not defined
This is called "traceback", and if you copy and paste it in your post asking
for help you provide us with a very useful means to debug your problem.
Without that we can only guess:
Did you call your own script
turtle.py
? Then it hides the "real" turtle module provided by Python.
Rename your script to myturtle.py, say, and it should work.
More information about the Tutor
mailing list