[Tutor] Fwd: Fwd: Turtle
Steven D'Aprano
steve at pearwood.info
Sun Jun 19 21:24:29 EDT 2016
On Sun, Jun 19, 2016 at 04:21:28PM -0700, Hershel Millman wrote:
> I entered "import turtle" instead of "from turtle import * ", but it
> looks as if it did not import the pendown command. Why is that?
Good question.
Try this:
import turtle
print(turtle.__file__)
That should print something like
'/usr/local/lib/python3.3/turtle.py'
or wherever you have installed Python to. If it is something like this:
/Users/Hershel/PycharmProjects/Project 1/turtle.py
then you have (accidentally) saved a new file called "turtle.py" and it
is shadowing the standard library file and blocking it from being
loading. Instead of importing the real turtle module, Python is
importing your fake turtle module.
To fix that, delete or rename your turtle.py module, quit PyCharm, and
start it up again.
Then you'll need to fix a small bug in your code:
> import turtle
>
> def drawSquare(size=100):
> turtle.pendown
Add round brackets (parentheses) to the pendown:
turtle.pendown()
Without the brackets, it just names the function, it doesn't call it. In
your case, it probably doesn't matter, since the turtle starts with the
pen down by default.
--
Steve
More information about the Tutor
mailing list